Skip to content

Commit 251f965

Browse files
authored
fix(client): Make action.workflowId optional on Schedule update (#1176)
1 parent 674c7e1 commit 251f965

File tree

4 files changed

+11
-13
lines changed

4 files changed

+11
-13
lines changed

packages/client/src/schedule-client.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,6 @@ function assertRequiredScheduleOptions(
149149
if (!opts.action.taskQueue) {
150150
throw new TypeError(`Missing ${structureName}.action.taskQueue for 'startWorkflow' action`);
151151
}
152-
if (!opts.action.workflowId && action === 'UPDATE') {
153-
throw new TypeError(`Missing ${structureName}.action.workflowId for 'startWorkflow' action`);
154-
}
155152
if (!opts.action.workflowType) {
156153
throw new TypeError(`Missing ${structureName}.action.workflowType for 'startWorkflow' action`);
157154
}
@@ -459,7 +456,11 @@ export class ScheduleClient extends BaseClient {
459456
const currentHeader: Headers = current.raw.schedule?.action?.startWorkflow?.header?.fields ?? {};
460457
const updated = updateFn(current);
461458
assertRequiredScheduleOptions(updated, 'UPDATE');
462-
await this.client._updateSchedule(scheduleId, compileUpdatedScheduleOptions(updated), currentHeader);
459+
await this.client._updateSchedule(
460+
scheduleId,
461+
compileUpdatedScheduleOptions(scheduleId, updated),
462+
currentHeader
463+
);
463464
},
464465

465466
async delete(): Promise<void> {

packages/client/src/schedule-helpers.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,13 +221,17 @@ export function compileScheduleOptions(options: ScheduleOptions): CompiledSchedu
221221
};
222222
}
223223

224-
export function compileUpdatedScheduleOptions(options: ScheduleUpdateOptions): CompiledScheduleUpdateOptions {
224+
export function compileUpdatedScheduleOptions(
225+
scheduleId: string,
226+
options: ScheduleUpdateOptions
227+
): CompiledScheduleUpdateOptions {
225228
const workflowTypeOrFunc = options.action.workflowType;
226229
const workflowType = extractWorkflowType(workflowTypeOrFunc);
227230
return {
228231
...options,
229232
action: {
230233
...options.action,
234+
workflowId: options.action.workflowId ?? `${scheduleId}-workflow`,
231235
workflowType,
232236
args: (options.action.args ?? []) as unknown[],
233237
},

packages/client/src/schedule-types.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,7 @@ export type CompiledScheduleOptions = Replace<
135135
export type ScheduleUpdateOptions<A extends ScheduleOptionsAction = ScheduleOptionsAction> = Replace<
136136
Omit<ScheduleOptions, 'scheduleId' | 'memo' | 'searchAttributes'>,
137137
{
138-
action: Replace<
139-
A,
140-
{
141-
// No default value on update
142-
workflowId: string;
143-
}
144-
>;
138+
action: A;
145139
state: Omit<ScheduleOptions['state'], 'triggerImmediately' | 'backfill'>;
146140
}
147141
>;

packages/test/src/test-schedules.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,6 @@ if (RUN_INTEGRATION_TESTS) {
396396
...x,
397397
action: {
398398
type: 'startWorkflow',
399-
workflowId: `${scheduleId}-workflow-2`,
400399
workflowType: dummyWorkflowWith2Args,
401400
args: [3, 4],
402401
taskQueue,

0 commit comments

Comments
 (0)