activity.go ×12

Frontier kind: Code frontier

unlabeled · c_05d90acac24d

4 tests · 2692 LOC · 131 files · introduces 0 tests · 52 LOC · 3 files

Introduces — evidence that enters the hierarchy at this concept

Code
15 ranges52 lines · 3 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
458 ranges2692 lines · 131 files · Browse complete extent
All tests (intent)
4 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

3 files ranked by introduced lines: 52 introduced LOC across 15 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

go.temporal.io/server/chasm/lib/activity/activity.go 43 introduced LOC · 12 ranges

Open complete file

168 activitypb.ACTIVITY_EXECUTION_STATUS_TERMINATED,
169 activitypb.ACTIVITY_EXECUTION_STATUS_TIMED_OUT,
170 > activitypb.ACTIVITY_EXECUTION_STATUS_CANCELED: activity.go
171 > return chasm.LifecycleStateFailed
172 default:
173 return chasm.LifecycleStateRunning
1318 overridingRetryInterval time.Duration,
1319 failure *failurepb.Failure,
1320 > ) (enumspb.RetryState, error) { activity.go
1321 > retryState, retryInterval := a.shouldRetry(ctx, overridingRetryInterval)
1322 > if !failureRetryable {
1323 retryState = enumspb.RETRY_STATE_NON_RETRYABLE_FAILURE
1324 }
1325 > resetRequested := a.GetStatus() == activitypb.ACTIVITY_EXECUTION_STATUS_RESET_REQUESTED activity.go
1326 > // A pending reset request is always honored, regardless of retryability or the should retry result.
1327 > if !resetRequested && retryState != enumspb.RETRY_STATE_IN_PROGRESS {
1328 > return retryState, nil
1329 > }
1330 retryIntervalSource := activitypb.ACTIVITY_RETRY_INTERVAL_SOURCE_RETRY_POLICY
1331 if overridingRetryInterval > 0 {
1346 }
1347
1348 > func (a *Activity) shouldRetry(ctx chasm.Context, overridingRetryInterval time.Duration) (enumspb.RetryState, time.Duration) { activity.go
1349 > if !TransitionRescheduled.Possible(a) &&
1350 > !TransitionAttemptFailedWhilePauseRequested.Possible(a) &&
1351 > !TransitionResetAttemptFailedToScheduled.Possible(a) &&
1352 > !TransitionResetAttemptFailedToPaused.Possible(a) {
1353 return enumspb.RETRY_STATE_UNSPECIFIED, 0
1354 }
1355 > attempt := a.LastAttempt.Get(ctx) activity.go
1356 > retryPolicy := a.RetryPolicy
1357 > enoughTime, retryInterval := a.hasEnoughTimeForRetry(ctx, overridingRetryInterval)
1358 >
1359 > if retryPolicy.GetMaximumAttempts() > 0 && attempt.GetCount() >= retryPolicy.GetMaximumAttempts() {
1360 return enumspb.RETRY_STATE_MAXIMUM_ATTEMPTS_REACHED, retryInterval
1361 }
1368 // hasEnoughTimeForRetry checks if there is enough time left in the schedule-to-close timeout. If sufficient time
1369 // remains, it will also return a valid retry interval.
1370 > func (a *Activity) hasEnoughTimeForRetry(ctx chasm.Context, overridingRetryInterval time.Duration) (bool, time.Duration) { activity.go
1371 > attempt := a.LastAttempt.Get(ctx)
1372 >
1373 > // Use overriding retry interval if provided, else calculate based on retry policy
1374 > retryInterval := overridingRetryInterval
1375 > if retryInterval <= 0 {
1376 > retryInterval = backoff.CalculateExponentialRetryInterval(a.RetryPolicy, attempt.Count)
1377 > }
1378
1379 > scheduleToClose := a.GetScheduleToCloseTimeout().AsDuration() activity.go
1380 > if scheduleToClose == 0 {
1381 return true, retryInterval
1382 }
1383
1384 > deadline := a.scheduleToCloseDeadline() activity.go
1385 > return ctx.Now(a).Add(retryInterval).Before(deadline), retryInterval
1386 }
1387
1857 // outcome retrieves the activity outcome (result or failure) if the activity has completed.
1858 // Returns nil if the activity has not completed.
1859 > func (a *Activity) outcome(ctx chasm.Context) *apiactivitypb.ActivityExecutionOutcome { activity.go
1860 > if !a.LifecycleState(ctx).IsClosed() {
1861 return nil
1862 }
1863 > activityOutcome := a.Outcome.Get(ctx) activity.go
1864 > if successful := activityOutcome.GetSuccessful(); successful != nil {
1865 return &apiactivitypb.ActivityExecutionOutcome{
1866 Value: &apiactivitypb.ActivityExecutionOutcome_Result{Result: successful.GetOutput()},
1867 }
1868 }
1869 > if failure := a.terminalFailure(ctx); failure != nil { activity.go
1870 > return &apiactivitypb.ActivityExecutionOutcome{
1871 > Value: &apiactivitypb.ActivityExecutionOutcome_Failure{Failure: failure},
1872 > }
1873 > }
1874 return nil
1875 }
1878 // (terminated, canceled, timed out) or in LastAttempt.LastFailureDetails (failed after exhausting retries).
1879 // Returns nil if no failure is found.
1880 > func (a *Activity) terminalFailure(ctx chasm.Context) *failurepb.Failure { activity.go
1881 > if f := a.Outcome.Get(ctx).GetFailed(); f != nil {
1882 return f.GetFailure()
1883 }
go.temporal.io/server/common/backoff/retry.go 8 introduced LOC · 2 ranges

Open complete file

194
195 // CalculateExponentialRetryInterval calculates the retry interval using exponential backoff algorithm
196 > func CalculateExponentialRetryInterval(retryPolicy *commonpb.RetryPolicy, attempt int32) time.Duration { retry.go
197 > interval := ExponentialBackoffAlgorithm(retryPolicy.GetInitialInterval(), retryPolicy.GetBackoffCoefficient(), attempt)
198 >
199 > maxInterval := retryPolicy.GetMaximumInterval()
200 >
201 > // Cap interval to maximum if it's set
202 > if maxInterval.AsDuration() != 0 && interval > maxInterval.AsDuration() {
203 interval = maxInterval.AsDuration()
204 }
205
206 > return interval retry.go
207 }
go.temporal.io/server/chasm/lib/activity/gen/activitypb/v1/activity_state.pb.go 1 introduced LOC · 1 range

Open complete file