Skip to content

Commit 64761ea

Browse files
authored
fix(workflow): do encode memos on continueAsNew (#955)
1 parent 5ebbcd3 commit 64761ea

File tree

5 files changed

+91
-6
lines changed

5 files changed

+91
-6
lines changed

packages/common/src/workflow-options.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export interface BaseWorkflowOptions {
7979
* Specifies additional non-indexed information to attach to the Workflow Execution. The values can be anything that
8080
* is serializable by {@link DataConverter}.
8181
*/
82-
memo?: Record<string, any>;
82+
memo?: Record<string, unknown>;
8383

8484
/**
8585
* Specifies additional indexed information to attach to the Workflow Execution. More info:

packages/test/src/integration-tests.ts

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,88 @@ export function runIntegrationTests(codec?: PayloadCodec): void {
872872
t.is(timeSlept, 1);
873873
});
874874

875+
test('continue-as-new-to-same-workflow keeps memo and search attributes', async (t) => {
876+
const { client } = t.context;
877+
const workflow = await client.start(workflows.continueAsNewSameWorkflow, {
878+
taskQueue: 'test',
879+
workflowId: uuid4(),
880+
memo: {
881+
note: 'foo',
882+
},
883+
searchAttributes: {
884+
CustomKeywordField: ['test-value'],
885+
CustomIntField: [1, 2],
886+
},
887+
followRuns: true,
888+
});
889+
await workflow.signal(workflows.continueAsNewSignal);
890+
await workflow.result();
891+
892+
const execution = await workflow.describe();
893+
t.not(execution.runId, workflow.firstExecutionRunId);
894+
t.deepEqual(execution.memo, { note: 'foo' });
895+
t.deepEqual(execution.searchAttributes!.CustomKeywordField, ['test-value']);
896+
t.deepEqual(execution.searchAttributes!.CustomIntField, [1, 2]);
897+
});
898+
899+
test('continue-as-new-to-different-workflow keeps memo and search attributes by default', async (t) => {
900+
const { client } = t.context;
901+
const workflow = await client.start(workflows.continueAsNewToDifferentWorkflow, {
902+
taskQueue: 'test',
903+
workflowId: uuid4(),
904+
followRuns: true,
905+
memo: {
906+
note: 'foo',
907+
},
908+
searchAttributes: {
909+
CustomKeywordField: ['test-value'],
910+
CustomIntField: [1, 2],
911+
},
912+
});
913+
await workflow.result();
914+
const info = await workflow.describe();
915+
t.is(info.type, 'sleeper');
916+
t.not(info.runId, workflow.firstExecutionRunId);
917+
t.deepEqual(info.memo, { note: 'foo' });
918+
t.deepEqual(info.searchAttributes!.CustomKeywordField, ['test-value']);
919+
t.deepEqual(info.searchAttributes!.CustomIntField, [1, 2]);
920+
});
921+
922+
test('continue-as-new-to-different-workflow can set memo and search attributes', async (t) => {
923+
const { client } = t.context;
924+
const workflow = await client.start(workflows.continueAsNewToDifferentWorkflow, {
925+
args: [
926+
1,
927+
{
928+
memo: {
929+
note: 'bar',
930+
},
931+
searchAttributes: {
932+
CustomKeywordField: ['test-value-2'],
933+
CustomIntField: [3, 4],
934+
},
935+
},
936+
],
937+
taskQueue: 'test',
938+
workflowId: uuid4(),
939+
followRuns: true,
940+
memo: {
941+
note: 'foo',
942+
},
943+
searchAttributes: {
944+
CustomKeywordField: ['test-value'],
945+
CustomIntField: [1, 2],
946+
},
947+
});
948+
await workflow.result();
949+
const info = await workflow.describe();
950+
t.is(info.type, 'sleeper');
951+
t.not(info.runId, workflow.firstExecutionRunId);
952+
t.deepEqual(info.memo, { note: 'bar' });
953+
t.deepEqual(info.searchAttributes!.CustomKeywordField, ['test-value-2']);
954+
t.deepEqual(info.searchAttributes!.CustomIntField, [3, 4]);
955+
});
956+
875957
test('signalWithStart works as intended and returns correct runId', async (t) => {
876958
const { client } = t.context;
877959
const ogWF = await client.signalWithStart(workflows.interruptableWorkflow, {

packages/test/src/workflows/continue-as-new-to-different-workflow.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22
* Tests continueAsNew to another Workflow
33
* @module
44
*/
5-
import { makeContinueAsNewFunc } from '@temporalio/workflow';
5+
import { ContinueAsNewOptions, makeContinueAsNewFunc } from '@temporalio/workflow';
66
import { sleeper } from './sleep';
77

8-
export async function continueAsNewToDifferentWorkflow(ms = 1): Promise<void> {
9-
const continueAsNew = makeContinueAsNewFunc<typeof sleeper>({ workflowType: 'sleeper' });
8+
export async function continueAsNewToDifferentWorkflow(
9+
ms = 1,
10+
extraArgs?: Partial<ContinueAsNewOptions>
11+
): Promise<void> {
12+
const continueAsNew = makeContinueAsNewFunc<typeof sleeper>({ workflowType: 'sleeper', ...(extraArgs ?? {}) });
1013
await continueAsNew(ms);
1114
}

packages/workflow/src/interfaces.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ export interface ContinueAsNewOptions {
189189
/**
190190
* Non-searchable attributes to attach to next Workflow run
191191
*/
192-
memo?: Record<string, any>;
192+
memo?: Record<string, unknown>;
193193
/**
194194
* Searchable attributes to attach to next Workflow run
195195
*/

packages/workflow/src/workflow.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,7 @@ export function makeContinueAsNewFunc<F extends Workflow>(
939939
arguments: toPayloads(activator.payloadConverter, ...args),
940940
headers,
941941
taskQueue: options.taskQueue,
942-
memo: options.memo,
942+
memo: options.memo && mapToPayloads(activator.payloadConverter, options.memo),
943943
searchAttributes: options.searchAttributes
944944
? mapToPayloads(searchAttributePayloadConverter, options.searchAttributes)
945945
: undefined,

0 commit comments

Comments
 (0)