From b854457fc9b80a688fd97b516a119f34c09287dc Mon Sep 17 00:00:00 2001 From: Fabian Martinez <46371672+famarting@users.noreply.github.com> Date: Tue, 3 Dec 2024 10:18:10 +0100 Subject: [PATCH] support set custom status Signed-off-by: Fabian Martinez <46371672+famarting@users.noreply.github.com> --- src/workflow/client/WorkflowState.ts | 10 ++++++++++ src/workflow/runtime/WorkflowContext.ts | 9 +++++++++ test/e2e/workflow/workflow.test.ts | 3 ++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/workflow/client/WorkflowState.ts b/src/workflow/client/WorkflowState.ts index 1b2181ff..814adcb4 100644 --- a/src/workflow/client/WorkflowState.ts +++ b/src/workflow/client/WorkflowState.ts @@ -105,4 +105,14 @@ export class WorkflowState { public get workflowFailureDetails(): WorkflowFailureDetails | undefined { return this._workflowFailureDetails; } + + + /** + * Gets the workflow instance's custom status, if any, as a string value. + * @returns {string | undefined} The workflow instance's custom status or undefined. + */ + public get customStatus(): string | undefined { + return this._orchestrationState.serializedCustomStatus; + } + } diff --git a/src/workflow/runtime/WorkflowContext.ts b/src/workflow/runtime/WorkflowContext.ts index 1213c1f1..90e848f8 100644 --- a/src/workflow/runtime/WorkflowContext.ts +++ b/src/workflow/runtime/WorkflowContext.ts @@ -156,6 +156,15 @@ export default class WorkflowContext { this._innerContext.continueAsNew(newInput, saveEvents); } + /** + * Sets the custom status + * + * @param status {string} The new custom status + */ + public setCustomStatus(status: string): void { + this._innerContext.setCustomStatus(status); + } + /** * Returns a task that completes when all of the provided tasks complete or when one of the tasks fail * diff --git a/test/e2e/workflow/workflow.test.ts b/test/e2e/workflow/workflow.test.ts index a881ba8c..d8c95f4c 100644 --- a/test/e2e/workflow/workflow.test.ts +++ b/test/e2e/workflow/workflow.test.ts @@ -76,7 +76,7 @@ describe("Workflow", () => { current = yield ctx.callActivity(plusOne, current); numbers.push(current); } - + ctx.setCustomStatus("foo"); return numbers; }; @@ -93,6 +93,7 @@ describe("Workflow", () => { expect(state?.runtimeStatus).toEqual(WorkflowRuntimeStatus.COMPLETED); expect(state?.serializedInput).toEqual(JSON.stringify(1)); expect(state?.serializedOutput).toEqual(JSON.stringify([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11])); + expect(state?.customStatus).toEqual("foo"); }, 31000); it("should be able to run fan-out/fan-in", async () => {