Skip to content

Commit b26bdcd

Browse files
committed
Address todos / add missed new file
1 parent 6b380c5 commit b26bdcd

File tree

10 files changed

+75
-31
lines changed

10 files changed

+75
-31
lines changed

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ env:
2020
# Use these variables to force specific version of CLI/Time Skipping Server for SDK tests
2121
# TESTS_CLI_VERSION: 'v0.13.2'
2222
TESTS_CLI_VERSION: 'v1.3.1-priority.0'
23-
# TESTS_TIME_SKIPPING_SERVER_VERSION: 'v1.3.1-priority.0'
23+
# TESTS_TIME_SKIPPING_SERVER_VERSION: 'v1.24.1'
2424

2525
jobs:
2626
# Compile native bridge code for each target platform.
+14-1
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,28 @@
11
/**
22
* Represents the version of a specific worker deployment.
33
*
4-
* @experimental Worker deployments are experimental
4+
* @experimental Deployment based versioning is experimental and may change in the future.
55
*/
66
export interface WorkerDeploymentVersion {
77
readonly buildId: string;
88
readonly deploymentName: string;
99
}
1010

11+
/**
12+
* @returns The canonical representation of a deployment version, which is a string in the format
13+
* `deploymentName.buildId`.
14+
*/
1115
export function toCanonicalString(version: WorkerDeploymentVersion): string {
1216
return `${version.deploymentName}.${version.buildId}`;
1317
}
1418

19+
/**
20+
* Specifies when a workflow might move from a worker of one Build Id to another.
21+
*
22+
* * 'pinned' - The workflow will be pinned to the current Build ID unless manually moved.
23+
* * 'auto-upgrade' - The workflow will automatically move to the latest version (default Build ID
24+
* of the task queue) when the next task is dispatched.
25+
*
26+
* @experimental Deployment based versioning is experimental and may change in the future.
27+
*/
1528
export type VersioningBehavior = 'pinned' | 'auto-upgrade';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { setHandler, condition } from '@temporalio/workflow';
2+
import { unblockSignal, versionQuery } from '../workflows';
3+
4+
export async function deploymentVersioning(): Promise<string> {
5+
let doFinish = false;
6+
setHandler(unblockSignal, () => void (doFinish = true));
7+
setHandler(versionQuery, () => 'v1');
8+
await condition(() => doFinish);
9+
return 'version-v1';
10+
}
11+
12+
export default async function (): Promise<string> {
13+
return 'dynamic';
14+
}

packages/test/src/helpers-integration.ts

-5
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,6 @@ export async function createLocalTestEnvironment(
101101
...(opts || {}), // Use provided options or default to an empty object
102102
server: {
103103
searchAttributes: Object.values(defaultSAKeys),
104-
// TODO: Remove after next CLI release
105-
executable: {
106-
type: 'cached-download',
107-
version: 'v1.3.1-priority.0',
108-
},
109104
...(opts?.server || {}), // Use provided server options or default to an empty object
110105
extraArgs: [
111106
...defaultDynamicConfigOptions.flatMap((opt) => ['--dynamic-config-value', opt]),

packages/test/src/test-worker-deployment-versioning.ts

+11-13
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ import assert from 'assert';
77
import { randomUUID } from 'crypto';
88
import asyncRetry from 'async-retry';
99
import { Client } from '@temporalio/client';
10+
import { toCanonicalString, WorkerDeploymentVersion } from '@temporalio/common';
11+
import { temporal } from '@temporalio/proto';
1012
import { Worker } from './helpers';
1113
import * as activities from './activities';
12-
import { toCanonicalString, WorkerDeploymentVersion } from '@temporalio/common';
1314
import { makeTestFunction } from './helpers-integration';
14-
import { unblockSignal, versionQuery } from './workflows/';
15-
import { temporal } from '@temporalio/proto';
15+
import { unblockSignal, versionQuery } from './workflows';
1616

1717
const test = makeTestFunction({ workflowsPath: __filename });
1818

@@ -23,15 +23,15 @@ test('Worker deployment based versioning', async (t) => {
2323

2424
const w1DeploymentVersion = {
2525
buildId: '1.0',
26-
deploymentName: deploymentName,
26+
deploymentName,
2727
};
2828
const w2DeploymentVersion = {
2929
buildId: '2.0',
30-
deploymentName: deploymentName,
30+
deploymentName,
3131
};
3232
const w3DeploymentVersion = {
3333
buildId: '3.0',
34-
deploymentName: deploymentName,
34+
deploymentName,
3535
};
3636

3737
const worker1 = await Worker.create({
@@ -144,11 +144,11 @@ test('Worker deployment based versioning with ramping', async (t) => {
144144

145145
const v1 = {
146146
buildId: '1.0',
147-
deploymentName: deploymentName,
147+
deploymentName,
148148
};
149149
const v2 = {
150150
buildId: '2.0',
151-
deploymentName: deploymentName,
151+
deploymentName,
152152
};
153153

154154
const worker1 = await Worker.create({
@@ -255,7 +255,7 @@ test('Worker deployment with dynamic workflow on run', async (t) => {
255255

256256
const version = {
257257
buildId: '1.0',
258-
deploymentName: deploymentName,
258+
deploymentName,
259259
};
260260

261261
const worker = await Worker.create({
@@ -264,7 +264,7 @@ test('Worker deployment with dynamic workflow on run', async (t) => {
264264
taskQueue,
265265
workerDeploymentOptions: {
266266
useWorkerVersioning: true,
267-
version: version,
267+
version,
268268
defaultVersioningBehavior: 'auto-upgrade',
269269
},
270270
});
@@ -308,7 +308,7 @@ test('Workflows can use default versioning behavior', async (t) => {
308308

309309
const workerV1 = {
310310
buildId: '1.0',
311-
deploymentName: deploymentName,
311+
deploymentName,
312312
};
313313

314314
const worker = await Worker.create({
@@ -337,9 +337,7 @@ test('Workflows can use default versioning behavior', async (t) => {
337337

338338
await wf.result();
339339

340-
// Check history for versioning behavior
341340
const history = await wf.fetchHistory();
342-
343341
const hasPinnedVersioningBehavior = history.events!.some(
344342
(event) =>
345343
event.workflowTaskCompletedEventAttributes &&

packages/worker/src/worker-options.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ export interface WorkerOptions {
123123

124124
/**
125125
* Deployment options for the worker. Exclusive with `build_id` and `use_worker_versioning`.
126-
126+
*
127127
* @experimental Deployment based versioning is still experimental.
128128
*/
129129
workerDeploymentOptions?: {

packages/worker/src/workflow/vm-shared.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ import * as internals from '@temporalio/workflow/lib/worker-interface';
1414
import { Activator } from '@temporalio/workflow/lib/internals';
1515
import { SdkFlags } from '@temporalio/workflow/lib/flags';
1616
import { UnhandledRejectionError } from '../errors';
17+
import { convertDeploymentVersion } from '../utils';
1718
import { Workflow } from './interface';
1819
import { WorkflowBundleWithSourceMapAndFilename } from './workflow-worker-thread/input';
19-
import { convertDeploymentVersion } from '../utils';
2020

2121
// Best effort to catch unhandled rejections from workflow code.
2222
// We crash the thread if we cannot find the culprit.

packages/workflow/src/interfaces.ts

+2
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@ export interface WorkflowInfo {
192192
* executing this task for the first time and has a Deployment Version set, then its ID will be
193193
* used. This value may change over the lifetime of the workflow run, but is deterministic and
194194
* safe to use for branching.
195+
*
196+
* @experimental Deployment based versioning is experimental and may change in the future.
195197
*/
196198
readonly currentDeploymentVersion?: WorkerDeploymentVersion;
197199

packages/workflow/src/internals.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ export class Activator implements ActivationHandler {
498498
return {
499499
commands: this.commands.splice(0),
500500
usedInternalFlags: [...this.knownFlags],
501-
versioningBehavior: versioningBehavior,
501+
versioningBehavior,
502502
};
503503
}
504504

packages/workflow/src/workflow.ts

+30-8
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import { versioningIntentToProto } from '@temporalio/common/lib/versioning-inten
3131
import { Duration, msOptionalToTs, msToNumber, msToTs, requiredTsToMs } from '@temporalio/common/lib/time';
3232
import { composeInterceptors } from '@temporalio/common/lib/interceptors';
3333
import { temporal } from '@temporalio/proto';
34+
import { WorkflowDefinitionOptions, WorkflowFunctionWithOptions } from '@temporalio/common';
3435
import { CancellationScope, registerSleepImplementation } from './cancellation-scope';
3536
import { UpdateScope } from './update-scope';
3637
import {
@@ -62,7 +63,6 @@ import { LocalActivityDoBackoff } from './errors';
6263
import { assertInWorkflowContext, getActivator, maybeGetActivator } from './global-attributes';
6364
import { untrackPromise } from './stack-helpers';
6465
import { ChildWorkflowHandle, ExternalWorkflowHandle } from './workflow-handle';
65-
import { WorkflowDefinitionOptions, WorkflowFunctionWithOptions } from '@temporalio/common';
6666

6767
// Avoid a circular dependency
6868
registerSleepImplementation(sleep);
@@ -1589,13 +1589,35 @@ export function allHandlersFinished(): boolean {
15891589
}
15901590

15911591
/**
1592-
* Can be used to define workflow functions with certain options specified at definition time.
1593-
1594-
* @param options Options for the workflow defintion.
1595-
* @param fn The workflow function.
1596-
* @returns The same passed in workflow function, with the specified options applied. You can export
1597-
* this function to make it available as a workflow function.
1598-
*/
1592+
* Can be used to alter or define workflow functions with certain options specified at definition
1593+
* time. In order to ensure that workflows are loaded properly by their name, you typically will not
1594+
* need to use the return value of this function.
1595+
*
1596+
* @example
1597+
* For example:
1598+
* ```ts
1599+
* defineWorkflowWithOptions({ versioningBehavior: 'pinned' }, myWorkflow);
1600+
* export async function myWorkflow(): Promise<string> {
1601+
* // Workflow code here
1602+
* return "hi";
1603+
* }
1604+
* ```
1605+
*
1606+
* @example
1607+
* To annotate a default or dynamic workflow:
1608+
* ```ts
1609+
* export default defineWorkflowWithOptions({ versioningBehavior: 'pinned' }, myDefaultWorkflow);
1610+
* async function myDefaultWorkflow(): Promise<string> {
1611+
* // Workflow code here
1612+
* return "hi";
1613+
* }
1614+
* ```
1615+
*
1616+
* @param options Options for the workflow defintion.
1617+
* @param fn The workflow function.
1618+
* @returns The same passed in workflow function, with the specified options applied. You can export
1619+
* this function to make it available as a workflow function.
1620+
*/
15991621
export function defineWorkflowWithOptions<A extends any[], RT>(
16001622
options: WorkflowDefinitionOptions,
16011623
fn: (...args: A) => Promise<RT>

0 commit comments

Comments
 (0)