Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Workflow Update #1277

Merged
merged 51 commits into from
Dec 5, 2023
Merged

Conversation

dandavison
Copy link
Contributor

@dandavison dandavison commented Oct 31, 2023

Fixes #1160

  • Implement support for Workflow Update

API

To see examples using the new API, see

Briefly:

// An Update is defined similarly to Query and Signal. The second type parameter (input) is optional
const myUpdate = wf.defineUpdate<string, [string]>('myUpdate');

// A handler is a sync or async function; the optional validator is always sync.
wf.setHandler(myUpdate, handler, { validator });

// `await wfHandle.executeUpdate` to start an update and block until it completes or fails.
// The signature resembles `WorkflowClient.start` in that the arguments are supplied
// in the optional options object
// (as opposed to the variadic signatures of wfHandle.query and wfHandle.signal)
// An error is thrown if the RPC times out (we do not poll for this call)
// or if the validator rejects, or the handler throws ApplicationFailure.
const updateResult = await handle.executeUpdate(myUpdate, { args: ['a'] });

// `startUpdate` to block until Accepted and obtain a handle to the Update. Signature the same as `executeUpdate`.
const updateHandle = await handle.startUpdate(myUpdate, { args: ['a'] });
// Blocking call to fetch result, with polling.
// Validation failures or ApplicationFailure in the handler would throw here.
const updateResult = await updateHandle.result();

How was this tested

Checklist

  1. Closes [Typescript] Workflow update support #1160

  2. Any docs updates needed?
    Yes

  3. Not done in this PR:

    • Test that non-ApplicationFailure error in handler fails the task
    • Tests involving continue-as-new (e.g. providing coverage for firstExecutionRunId)
    • Support late registration
    • Fail task if workflow commands created during validation
    • Support setting a default update handler

@dandavison dandavison requested a review from a team as a code owner October 31, 2023 17:57
packages/client/src/interceptors.ts Outdated Show resolved Hide resolved
packages/client/src/workflow-client.ts Outdated Show resolved Hide resolved
packages/client/src/workflow-client.ts Show resolved Hide resolved
// expiry. See https://github.com/temporalio/temporal/issues/4742

// TODO: When temporal#4742 is released, stop catching DEADLINE_EXCEEDED.
while (true) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May also want a TODO concerning supporting user-facing cancellation on long-poll/RPC-loop calls (AbortSignal I think was what was decided) and a link to the issue (or make one)

packages/client/src/workflow-client.ts Outdated Show resolved Hide resolved
packages/core-bridge/src/conversions.rs Outdated Show resolved Hide resolved
packages/workflow/src/internals.ts Outdated Show resolved Hide resolved
packages/workflow/src/internals.ts Outdated Show resolved Hide resolved
packages/workflow/src/interceptors.ts Show resolved Hide resolved
packages/workflow/src/interceptors.ts Show resolved Hide resolved
packages/client/src/workflow-client.ts Outdated Show resolved Hide resolved
packages/client/src/workflow-client.ts Outdated Show resolved Hide resolved
packages/client/src/workflow-client.ts Outdated Show resolved Hide resolved
protected async _executeUpdateHandler<Ret>(input: WorkflowUpdateInput): Promise<Ret> {
const handle = await this._startUpdate<Ret>(
input,
temporal.api.enums.v1.UpdateWorkflowExecutionLifecycleStage.UPDATE_WORKFLOW_EXECUTION_LIFECYCLE_STAGE_COMPLETED
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want to have a type alias here to avoid this long statement.

packages/client/src/workflow-client.ts Show resolved Hide resolved
packages/workflow/src/internals.ts Outdated Show resolved Hide resolved
packages/workflow/src/internals.ts Outdated Show resolved Hide resolved
packages/workflow/src/internals.ts Outdated Show resolved Hide resolved
packages/workflow/src/internals.ts Outdated Show resolved Hide resolved
packages/workflow/src/internals.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@lorensr lorensr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yay! 💃

packages/client/src/workflow-client.ts Outdated Show resolved Hide resolved
packages/client/src/workflow-client.ts Show resolved Hide resolved
packages/client/src/workflow-client.ts Outdated Show resolved Hide resolved
packages/client/src/workflow-client.ts Outdated Show resolved Hide resolved
packages/client/src/workflow-client.ts Outdated Show resolved Hide resolved
packages/client/src/workflow-options.ts Outdated Show resolved Hide resolved
@dandavison dandavison force-pushed the sdk-879-workflow-update branch 3 times, most recently from 9a11f66 to 2ddfae5 Compare November 9, 2023 17:38
Copy link
Member

@bergundy bergundy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we agreed to mark all of the update APIs experimental, please do so.

packages/client/src/interceptors.ts Show resolved Hide resolved
packages/client/src/workflow-client.ts Show resolved Hide resolved
packages/client/src/workflow-client.ts Outdated Show resolved Hide resolved
packages/client/src/workflow-client.ts Outdated Show resolved Hide resolved
packages/client/src/workflow-client.ts Show resolved Hide resolved
packages/worker/src/workflow-codec-runner.ts Show resolved Hide resolved
packages/workflow/src/internals.ts Show resolved Hide resolved
packages/workflow/src/internals.ts Outdated Show resolved Hide resolved
packages/workflow/src/internals.ts Outdated Show resolved Hide resolved
packages/workflow/src/internals.ts Outdated Show resolved Hide resolved
Copy link
Member

@bergundy bergundy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Meant to comment before, accidentally approved.

@dandavison
Copy link
Contributor Author

In addition to the tests here, this PR passes the features tests for TS in temporalio/features#362

if (!name) {
throw new TypeError('Missing activation update name');
}
if (!protocolInstanceId) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: You could have combine all of those checks into a single "Misformed activation" error. Being very detailed is useful for user provided objects (ie. errors are more likely, are user need to know what they need to fix), but here, a missing field would indicate a server/core level error.

Copy link
Contributor

@mjameswh mjameswh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make sure to fix the four floating promises before you merge. Otherwise, just a suggestion, don't feel obliged.

Great job, thanks a lot!

@dandavison dandavison merged commit 22a8f1d into temporalio:main Dec 5, 2023
24 checks passed
@dandavison
Copy link
Contributor Author

Thanks @mjameswh and @bergundy for all the reviewing here!

mjameswh pushed a commit to mjameswh/sdk-typescript that referenced this pull request Dec 6, 2023
Pure refactoring of the integration tests, done in preparation for implementation of Workflow Update in temporalio#1277.
@dandavison dandavison mentioned this pull request Dec 7, 2023
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Typescript] Workflow update support
6 participants