Skip to content

Commit 8112c9f

Browse files
authored
fix(worker): Validate buildId is set when useVersioning is true (#1207)
1 parent 833f99e commit 8112c9f

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
11
import test from 'ava';
22
import { reachabilityResponseFromProto, UnversionedBuildId } from '@temporalio/client/lib/task-queue-client';
33
import { temporal } from '@temporalio/proto';
4+
import { Worker } from '@temporalio/worker';
45

56
const TaskReachability = temporal.api.enums.v1.TaskReachability;
67
const GetWorkerTaskReachabilityResponse = temporal.api.workflowservice.v1.GetWorkerTaskReachabilityResponse;
78

9+
test('Worker.create fails if useVersioning is true and not provided a buildId', async (t) => {
10+
const err = await t.throwsAsync(() =>
11+
Worker.create({
12+
taskQueue: 'foo',
13+
useVersioning: true,
14+
})
15+
);
16+
t.true(err instanceof TypeError);
17+
t.is(err?.message, 'Must provide a buildId if useVersioning is true');
18+
});
19+
820
test('Worker versioning workers get appropriate tasks', async (t) => {
921
const res = reachabilityResponseFromProto(
1022
GetWorkerTaskReachabilityResponse.create({

packages/worker/src/worker-options.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ export interface WorkerOptions {
8686
* {@link WorkerOptions.useVersioning}. It will also populate the `binaryChecksum` field
8787
* on older servers.
8888
*
89+
* ℹ️ Required if {@link useVersioning} is `true`.
90+
*
8991
* @default `@temporalio/worker` package name and version + checksum of workflow bundle's code
9092
*
9193
* @experimental
@@ -636,7 +638,16 @@ export function appendDefaultInterceptors(
636638
}
637639

638640
export function addDefaultWorkerOptions(options: WorkerOptions): WorkerOptionsWithDefaults {
639-
const { maxCachedWorkflows, showStackTraceSources, namespace, reuseV8Context, sinks, ...rest } = options;
641+
const {
642+
buildId,
643+
useVersioning,
644+
maxCachedWorkflows,
645+
showStackTraceSources,
646+
namespace,
647+
reuseV8Context,
648+
sinks,
649+
...rest
650+
} = options;
640651
const debugMode = options.debugMode || isSet(process.env.TEMPORAL_DEBUG);
641652
const maxConcurrentWorkflowTaskExecutions = options.maxConcurrentWorkflowTaskExecutions ?? 40;
642653
const maxConcurrentActivityTaskExecutions = options.maxConcurrentActivityTaskExecutions ?? 100;
@@ -646,10 +657,15 @@ export function addDefaultWorkerOptions(options: WorkerOptions): WorkerOptionsWi
646657
? Math.max(Math.floor((Math.max(heapSizeMiB - 200, 0) * 600) / 1024), 10)
647658
: Math.max(Math.floor((Math.max(heapSizeMiB - 400, 0) * 250) / 1024), 10);
648659

660+
if (useVersioning && !buildId) {
661+
throw new TypeError('Must provide a buildId if useVersioning is true');
662+
}
663+
649664
return {
650665
namespace: namespace ?? 'default',
651666
identity: `${process.pid}@${os.hostname()}`,
652-
useVersioning: options.useVersioning ?? false,
667+
useVersioning: useVersioning ?? false,
668+
buildId,
653669
shutdownGraceTime: 0,
654670
maxConcurrentLocalActivityExecutions: 100,
655671
enableNonLocalActivities: true,

0 commit comments

Comments
 (0)