Skip to content

Commit c9d28ed

Browse files
committed
Use more standard enum representation / fix related errors
1 parent f39ec3f commit c9d28ed

File tree

9 files changed

+53
-27
lines changed

9 files changed

+53
-27
lines changed

packages/common/src/worker-deployments.ts

+23-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import { temporal } from '@temporalio/proto';
2+
import { makeProtoEnumConverters } from './internal-workflow';
3+
14
/**
25
* Represents the version of a specific worker deployment.
36
*
@@ -25,4 +28,23 @@ export function toCanonicalString(version: WorkerDeploymentVersion): string {
2528
*
2629
* @experimental Deployment based versioning is experimental and may change in the future.
2730
*/
28-
export type VersioningBehavior = 'pinned' | 'auto-upgrade';
31+
export const VersioningBehavior = {
32+
PINNED: 'PINNED',
33+
AUTO_UPGRADE: 'AUTO_UPGRADE',
34+
} as const;
35+
export type VersioningBehavior = (typeof VersioningBehavior)[keyof typeof VersioningBehavior];
36+
37+
export const [encodeVersioningBehavior, decodeVersioningBehavior] = makeProtoEnumConverters<
38+
temporal.api.enums.v1.VersioningBehavior,
39+
typeof temporal.api.enums.v1.VersioningBehavior,
40+
keyof typeof temporal.api.enums.v1.VersioningBehavior,
41+
typeof VersioningBehavior,
42+
'VERSIONING_BEHAVIOR_'
43+
>(
44+
{
45+
[VersioningBehavior.PINNED]: 1,
46+
[VersioningBehavior.AUTO_UPGRADE]: 2,
47+
UNSPECIFIED: 0,
48+
} as const,
49+
'VERSIONING_BEHAVIOR_'
50+
);

packages/core-bridge/src/conversions.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -531,8 +531,8 @@ impl ObjectHandleConversionsExt for Handle<'_, JsObject> {
531531
let default_versioning_behavior =
532532
js_optional_value_getter!(cx, &dopts, "defaultVersioningBehavior", JsString);
533533
let default_versioning_behavior = match default_versioning_behavior.as_deref() {
534-
Some("pinned") => Some(VersioningBehavior::Pinned),
535-
Some("auto-upgrade") => Some(VersioningBehavior::AutoUpgrade),
534+
Some("PINNED") => Some(VersioningBehavior::Pinned),
535+
Some("AUTO_UPGRADE") => Some(VersioningBehavior::AutoUpgrade),
536536
None => None,
537537
_ => return cx.throw_error("Invalid default versioning behavior"),
538538
};
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { setHandler, condition, defineWorkflowWithOptions } from '@temporalio/workflow';
22
import { unblockSignal, versionQuery } from '../workflows';
33

4-
defineWorkflowWithOptions({ versioningBehavior: 'auto-upgrade' }, deploymentVersioning);
4+
defineWorkflowWithOptions({ versioningBehavior: 'AUTO_UPGRADE' }, deploymentVersioning);
55
export async function deploymentVersioning(): Promise<string> {
66
let doFinish = false;
77
setHandler(unblockSignal, () => void (doFinish = true));
@@ -11,7 +11,7 @@ export async function deploymentVersioning(): Promise<string> {
1111
}
1212

1313
// Dynamic/default workflow handler
14-
export default defineWorkflowWithOptions({ versioningBehavior: 'pinned' }, _default);
14+
export default defineWorkflowWithOptions({ versioningBehavior: 'PINNED' }, _default);
1515
async function _default(): Promise<string> {
1616
return 'dynamic';
1717
}

packages/test/src/deployment-versioning-v2/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { setHandler, condition, defineWorkflowWithOptions } from '@temporalio/workflow';
22
import { unblockSignal, versionQuery } from '../workflows';
33

4-
defineWorkflowWithOptions({ versioningBehavior: 'pinned' }, deploymentVersioning);
4+
defineWorkflowWithOptions({ versioningBehavior: 'PINNED' }, deploymentVersioning);
55
export async function deploymentVersioning(): Promise<string> {
66
let doFinish = false;
77
setHandler(unblockSignal, () => void (doFinish = true));

packages/test/src/deployment-versioning-v3/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { setHandler, condition, defineWorkflowWithOptions } from '@temporalio/workflow';
22
import { unblockSignal, versionQuery } from '../workflows';
33

4-
defineWorkflowWithOptions({ versioningBehavior: 'auto-upgrade' }, deploymentVersioning);
4+
defineWorkflowWithOptions({ versioningBehavior: 'AUTO_UPGRADE' }, deploymentVersioning);
55
export async function deploymentVersioning(): Promise<string> {
66
let doFinish = false;
77
setHandler(unblockSignal, () => void (doFinish = true));

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

+7-7
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ test('Worker deployment based versioning', async (t) => {
3939
workerDeploymentOptions: {
4040
useWorkerVersioning: true,
4141
version: w1DeploymentVersion,
42-
defaultVersioningBehavior: 'pinned',
42+
defaultVersioningBehavior: 'PINNED',
4343
},
4444
});
4545
const worker1Promise = worker1.run();
@@ -53,7 +53,7 @@ test('Worker deployment based versioning', async (t) => {
5353
workerDeploymentOptions: {
5454
useWorkerVersioning: true,
5555
version: w2DeploymentVersion,
56-
defaultVersioningBehavior: 'pinned',
56+
defaultVersioningBehavior: 'PINNED',
5757
},
5858
});
5959
const worker2Promise = worker2.run();
@@ -67,7 +67,7 @@ test('Worker deployment based versioning', async (t) => {
6767
workerDeploymentOptions: {
6868
useWorkerVersioning: true,
6969
version: w3DeploymentVersion,
70-
defaultVersioningBehavior: 'pinned',
70+
defaultVersioningBehavior: 'PINNED',
7171
},
7272
});
7373
const worker3Promise = worker3.run();
@@ -153,7 +153,7 @@ test('Worker deployment based versioning with ramping', async (t) => {
153153
workerDeploymentOptions: {
154154
useWorkerVersioning: true,
155155
version: v1,
156-
defaultVersioningBehavior: 'pinned',
156+
defaultVersioningBehavior: 'PINNED',
157157
},
158158
});
159159
const worker1Promise = worker1.run();
@@ -167,7 +167,7 @@ test('Worker deployment based versioning with ramping', async (t) => {
167167
workerDeploymentOptions: {
168168
useWorkerVersioning: true,
169169
version: v2,
170-
defaultVersioningBehavior: 'pinned',
170+
defaultVersioningBehavior: 'PINNED',
171171
},
172172
});
173173
const worker2Promise = worker2.run();
@@ -258,7 +258,7 @@ test('Worker deployment with dynamic workflow on run', async (t) => {
258258
workerDeploymentOptions: {
259259
useWorkerVersioning: true,
260260
version,
261-
defaultVersioningBehavior: 'auto-upgrade',
261+
defaultVersioningBehavior: 'AUTO_UPGRADE',
262262
},
263263
});
264264

@@ -310,7 +310,7 @@ test('Workflows can use default versioning behavior', async (t) => {
310310
workerDeploymentOptions: {
311311
useWorkerVersioning: true,
312312
version: workerV1,
313-
defaultVersioningBehavior: 'pinned',
313+
defaultVersioningBehavior: 'PINNED',
314314
},
315315
});
316316

packages/workflow/src/interfaces.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ import {
1414
SearchAttributePair,
1515
Priority,
1616
WorkerDeploymentVersion,
17+
VersioningBehavior,
1718
} from '@temporalio/common';
1819
import { SymbolBasedInstanceOfError } from '@temporalio/common/lib/type-helpers';
1920
import { makeProtoEnumConverters } from '@temporalio/common/lib/internal-workflow/enums-helpers';
20-
import type { coresdk, temporal } from '@temporalio/proto';
21+
import type { coresdk } from '@temporalio/proto';
2122

2223
/**
2324
* Workflow Execution information
@@ -612,5 +613,5 @@ export type UpdateHandlerOptions<Args extends any[]> = {
612613
export interface ActivationCompletion {
613614
commands: coresdk.workflow_commands.IWorkflowCommand[];
614615
usedInternalFlags: number[];
615-
versioningBehavior?: temporal.api.enums.v1.VersioningBehavior;
616+
versioningBehavior?: VersioningBehavior;
616617
}

packages/workflow/src/internals.ts

+2-8
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import {
2929
} from '@temporalio/common/lib/converter/payload-search-attributes';
3030
import { composeInterceptors } from '@temporalio/common/lib/interceptors';
3131
import { makeProtoEnumConverters } from '@temporalio/common/lib/internal-workflow';
32-
import { coresdk, temporal } from '@temporalio/proto';
32+
import type { coresdk, temporal } from '@temporalio/proto';
3333
import { alea, RNG } from './alea';
3434
import { RootCancellationScope } from './cancellation-scope';
3535
import { UpdateScope } from './update-scope';
@@ -489,16 +489,10 @@ export class Activator implements ActivationHandler {
489489
}
490490

491491
concludeActivation(): ActivationCompletion {
492-
let versioningBehavior;
493-
if (this.versioningBehavior === 'auto-upgrade') {
494-
versioningBehavior = temporal.api.enums.v1.VersioningBehavior.VERSIONING_BEHAVIOR_AUTO_UPGRADE;
495-
} else if (this.versioningBehavior === 'pinned') {
496-
versioningBehavior = temporal.api.enums.v1.VersioningBehavior.VERSIONING_BEHAVIOR_PINNED;
497-
}
498492
return {
499493
commands: this.commands.splice(0),
500494
usedInternalFlags: [...this.knownFlags],
501-
versioningBehavior,
495+
versioningBehavior: this.versioningBehavior,
502496
};
503497
}
504498

packages/workflow/src/worker-interface.ts

+12-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@
33
*
44
* @module
55
*/
6-
import { IllegalStateError, isWorkflowFunctionWithOptions } from '@temporalio/common';
6+
import {
7+
encodeVersioningBehavior,
8+
IllegalStateError,
9+
isWorkflowFunctionWithOptions,
10+
VersioningBehavior,
11+
} from '@temporalio/common';
712
import { composeInterceptors } from '@temporalio/common/lib/interceptors';
8-
import { coresdk } from '@temporalio/proto';
13+
import { coresdk, temporal } from '@temporalio/proto';
914
import { disableStorage } from './cancellation-scope';
1015
import { disableUpdateStorage } from './update-scope';
1116
import { WorkflowInterceptorsFactory } from './interceptors';
@@ -209,7 +214,11 @@ export function concludeActivation(): coresdk.workflow_completion.IWorkflowActiv
209214
}
210215
return {
211216
runId: activator.info.runId,
212-
successful: { ...activationCompletion, commands },
217+
successful: {
218+
...activationCompletion,
219+
commands,
220+
versioningBehavior: encodeVersioningBehavior(activationCompletion.versioningBehavior),
221+
},
213222
};
214223
} finally {
215224
activator.rethrowSynchronously = false;

0 commit comments

Comments
 (0)