-
Notifications
You must be signed in to change notification settings - Fork 138
Activity pause/unpause #1729
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Activity pause/unpause #1729
Changes from 11 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
0a29eb2
impl
THardy98 8787f57
add pause error for external activity heartbeating
THardy98 582e4f0
add logging for activity pause, emit application failure on activity …
THardy98 9f7f0da
add 'reset' to activity cancellation details
THardy98 a9a9339
add tests
THardy98 e53fad6
Merge branch 'main' into activity_pause_unpause
THardy98 e79f51e
make 'cancel' in mock activity env more well-defined, make cancellati…
THardy98 6bbf135
Merge branch 'main' into activity_pause_unpause
THardy98 589cae8
formatting/linting
THardy98 5e62013
mock activity hb test fix
THardy98 d62e139
bump pause helper timeout
THardy98 e1431f2
address review suggestions
THardy98 fa0afb9
Merge branch 'main' into activity_pause_unpause
THardy98 9569714
ignore ts prune
THardy98 3ee7227
simplify cancellation details tests, reduce flakiness
THardy98 6a33699
Merge branch 'main' into activity_pause_unpause
THardy98 e93afc3
simplify further, eliminate flakiness
THardy98 30f050d
linting
THardy98 052e887
Merge branch 'main' into activity_pause_unpause
THardy98 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import type { coresdk } from '@temporalio/proto'; | ||
|
|
||
| export interface ActivityCancellationDetailsHolder { | ||
| details?: ActivityCancellationDetails; | ||
| } | ||
|
|
||
| export interface ActivityCancellationDetailsOptions { | ||
| notFound?: boolean; | ||
| cancelRequested?: boolean; | ||
| paused?: boolean; | ||
| timedOut?: boolean; | ||
| workerShutdown?: boolean; | ||
| reset?: boolean; | ||
| } | ||
|
|
||
| /** | ||
| * Provides the reasons for the activity's cancellation. Cancellation details are set once and do not change once set. | ||
| */ | ||
| export class ActivityCancellationDetails { | ||
| readonly notFound: boolean; | ||
| readonly cancelRequested: boolean; | ||
| readonly paused: boolean; | ||
| readonly timedOut: boolean; | ||
| readonly workerShutdown: boolean; | ||
| readonly reset: boolean; | ||
|
|
||
| public constructor(options: ActivityCancellationDetailsOptions = {}) { | ||
| this.notFound = options.notFound ?? false; | ||
| this.cancelRequested = options.cancelRequested ?? false; | ||
| this.paused = options.paused ?? false; | ||
| this.timedOut = options.timedOut ?? false; | ||
| this.workerShutdown = options.workerShutdown ?? false; | ||
| this.reset = options.reset ?? false; | ||
| } | ||
|
|
||
| static fromProto( | ||
| proto: coresdk.activity_task.IActivityCancellationDetails | null | undefined | ||
| ): ActivityCancellationDetails { | ||
| if (proto == null) { | ||
| return new ActivityCancellationDetails(); | ||
| } | ||
| return new ActivityCancellationDetails({ | ||
| notFound: proto.isNotFound ?? false, | ||
| cancelRequested: proto.isCancelled ?? false, | ||
| paused: proto.isPaused ?? false, | ||
| timedOut: proto.isTimedOut ?? false, | ||
| workerShutdown: proto.isWorkerShutdown ?? false, | ||
| reset: proto.isReset ?? false, | ||
| }); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
packages/test/src/activities/heartbeat-cancellation-details.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import { ActivityCancellationDetails } from '@temporalio/common'; | ||
| import * as activity from '@temporalio/activity'; | ||
|
|
||
| export async function heartbeatCancellationDetailsActivity( | ||
| catchErr: boolean | ||
| ): Promise<ActivityCancellationDetails | undefined> { | ||
| // Exit early if we've already run this activity. | ||
| if (activity.activityInfo().heartbeatDetails === 'finally-complete') { | ||
| return activity.cancellationDetails(); | ||
| } | ||
| // eslint-disable-next-line no-constant-condition | ||
| while (true) { | ||
| try { | ||
| activity.heartbeat(); | ||
| await activity.sleep(300); | ||
| } catch (err) { | ||
| if (err instanceof activity.CancelledFailure && catchErr) { | ||
| return activity.cancellationDetails(); | ||
| } | ||
| activity.heartbeat('finally-complete'); | ||
| throw err; | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.