Skip to content

Commit 8169797

Browse files
committed
Versioning override
1 parent 37bcf27 commit 8169797

File tree

3 files changed

+48
-8
lines changed

3 files changed

+48
-8
lines changed

packages/client/src/workflow-options.ts

+36-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1-
import { CommonWorkflowOptions, SignalDefinition, WithWorkflowArgs, Workflow } from '@temporalio/common';
1+
import {
2+
CommonWorkflowOptions,
3+
SignalDefinition,
4+
WithWorkflowArgs,
5+
Workflow,
6+
VersioningOverride,
7+
toCanonicalString,
8+
} from '@temporalio/common';
29
import { Duration, msOptionalToTs } from '@temporalio/common/lib/time';
310
import { Replace } from '@temporalio/common/lib/type-helpers';
4-
import { google } from '@temporalio/proto';
11+
import { google, temporal } from '@temporalio/proto';
512

613
export * from '@temporalio/common/lib/workflow-options';
714

@@ -38,9 +45,15 @@ export interface WorkflowOptions extends CommonWorkflowOptions {
3845

3946
/**
4047
* Amount of time to wait before starting the workflow.
41-
*
4248
*/
4349
startDelay?: Duration;
50+
51+
/**
52+
* Override the versioning behavior of the Workflow that is about to be started.
53+
*
54+
* @experimental Deployment based versioning is experimental and may change in the future.
55+
*/
56+
versioningOverride?: VersioningOverride;
4457
}
4558

4659
export type WithCompiledWorkflowOptions<T extends WorkflowOptions> = Replace<
@@ -50,18 +63,21 @@ export type WithCompiledWorkflowOptions<T extends WorkflowOptions> = Replace<
5063
workflowRunTimeout?: google.protobuf.IDuration;
5164
workflowTaskTimeout?: google.protobuf.IDuration;
5265
startDelay?: google.protobuf.IDuration;
66+
versioningOverride?: temporal.api.workflow.v1.IVersioningOverride;
5367
}
5468
>;
5569

5670
export function compileWorkflowOptions<T extends WorkflowOptions>(options: T): WithCompiledWorkflowOptions<T> {
57-
const { workflowExecutionTimeout, workflowRunTimeout, workflowTaskTimeout, startDelay, ...rest } = options;
71+
const { workflowExecutionTimeout, workflowRunTimeout, workflowTaskTimeout, startDelay, versioningOverride, ...rest } =
72+
options;
5873

5974
return {
6075
...rest,
6176
workflowExecutionTimeout: msOptionalToTs(workflowExecutionTimeout),
6277
workflowRunTimeout: msOptionalToTs(workflowRunTimeout),
6378
workflowTaskTimeout: msOptionalToTs(workflowTaskTimeout),
6479
startDelay: msOptionalToTs(startDelay),
80+
versioningOverride: versioningOverrideToProto(versioningOverride),
6581
};
6682
}
6783

@@ -109,3 +125,19 @@ export interface WorkflowSignalWithStartOptionsWithArgs<SignalArgs extends any[]
109125
* Options for starting a Workflow
110126
*/
111127
export type WorkflowStartOptions<T extends Workflow = Workflow> = WithWorkflowArgs<T, WorkflowOptions>;
128+
129+
function versioningOverrideToProto(
130+
vo: VersioningOverride | undefined
131+
): temporal.api.workflow.v1.IVersioningOverride | undefined {
132+
if (!vo) return undefined;
133+
// TODO: Remove deprecated field assignments when versioning is non-experimental
134+
if (vo === 'AUTO_UPGRADE') {
135+
return {
136+
behavior: temporal.api.enums.v1.VersioningBehavior.VERSIONING_BEHAVIOR_AUTO_UPGRADE,
137+
};
138+
}
139+
return {
140+
behavior: temporal.api.enums.v1.VersioningBehavior.VERSIONING_BEHAVIOR_PINNED,
141+
pinnedVersion: toCanonicalString(vo.version),
142+
};
143+
}

packages/common/src/worker-deployments.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ export function toCanonicalString(version: WorkerDeploymentVersion): string {
2222
/**
2323
* Specifies when a workflow might move from a worker of one Build Id to another.
2424
*
25-
* * 'pinned' - The workflow will be pinned to the current Build ID unless manually moved.
26-
* * 'auto-upgrade' - The workflow will automatically move to the latest version (default Build ID
25+
* * 'PINNED' - The workflow will be pinned to the current Build ID unless manually moved.
26+
* * 'AUTO_UPGRADE' - The workflow will automatically move to the latest version (default Build ID
2727
* of the task queue) when the next task is dispatched.
2828
*
2929
* @experimental Deployment based versioning is experimental and may change in the future.
@@ -48,3 +48,12 @@ export const [encodeVersioningBehavior, decodeVersioningBehavior] = makeProtoEnu
4848
} as const,
4949
'VERSIONING_BEHAVIOR_'
5050
);
51+
52+
/**
53+
* Represents versioning overrides. For example, when starting workflows.
54+
*
55+
* If set to 'AUTO_UPGRADE', the Workflow will run as if it is using {@link VersioningBehavior.AUTO_UPGRADE}.
56+
* Otherwise, you select a pinned behavior, and a specific version to pin to. Currently only one
57+
* such behavior exists, but more will be added in the future.
58+
*/
59+
export type VersioningOverride = { pinned_behavior: 'PINNED'; version: WorkerDeploymentVersion } | 'AUTO_UPGRADE';

packages/workflow/src/workflow.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import {
2424
SearchAttributeUpdatePair,
2525
compilePriority,
2626
WorkflowDefinitionOptionsOrGetter,
27-
WorkflowFunctionWithOptions,
2827
} from '@temporalio/common';
2928
import {
3029
encodeUnifiedSearchAttributes,
@@ -1623,7 +1622,7 @@ export function allHandlersFinished(): boolean {
16231622
export function setWorkflowOptions<A extends any[], RT>(
16241623
options: WorkflowDefinitionOptionsOrGetter,
16251624
fn: (...args: A) => Promise<RT>
1626-
) {
1625+
): void {
16271626
Object.assign(fn, {
16281627
workflowDefinitionOptions: options,
16291628
});

0 commit comments

Comments
 (0)