From 31d0ef567fb98e06e482bebad5ff7065be9b6b4f Mon Sep 17 00:00:00 2001 From: allanhvam Date: Tue, 13 Aug 2024 10:46:31 +0200 Subject: [PATCH] fix: check runtime status in durable functions store getInstances --- package-lock.json | 4 ++-- package.json | 2 +- .../DurableFunctionsWorkflowHistoryStore.ts | 9 ++++++- src/tests/store.test.ts | 24 +++++++++++++++++++ 4 files changed, 35 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index 3aa77f2..1ec4665 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "simple-workflows", - "version": "0.1.0-beta16", + "version": "0.1.0-beta17", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "simple-workflows", - "version": "0.1.0-beta16", + "version": "0.1.0-beta17", "license": "MIT", "dependencies": { "@azure/data-tables": "^13.0.1", diff --git a/package.json b/package.json index 309d35b..d4cf7f0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "simple-workflows", - "version": "0.1.0-beta16", + "version": "0.1.0-beta17", "description": "Workflows as code in TypeScript", "main": "lib/index.js", "type": "module", diff --git a/src/stores/DurableFunctionsWorkflowHistoryStore.ts b/src/stores/DurableFunctionsWorkflowHistoryStore.ts index 66890b6..d0a658c 100644 --- a/src/stores/DurableFunctionsWorkflowHistoryStore.ts +++ b/src/stores/DurableFunctionsWorkflowHistoryStore.ts @@ -467,7 +467,13 @@ export class DurableFunctionsWorkflowHistoryStore extends SerializedWorkflowHist { queryOptions: { filter: queryFilters.join(" and "), - select: ["Name", "CustomStatus", "CreatedTime", "CompletedTime"], + select: [ + "Name", + "CustomStatus", + "CreatedTime", + "CompletedTime", + "RuntimeStatus", + ], }, }, ).byPage({ @@ -486,6 +492,7 @@ export class DurableFunctionsWorkflowHistoryStore extends SerializedWorkflowHist status: instance.CustomStatus === "timeout" ? "timeout" : undefined, start: instance.CreatedTime, end: instance.CompletedTime, + error: instance.RuntimeStatus === "Failed", }; instances.push(header); diff --git a/src/tests/store.test.ts b/src/tests/store.test.ts index 1995393..77be24f 100644 --- a/src/tests/store.test.ts +++ b/src/tests/store.test.ts @@ -4,6 +4,7 @@ import { Worker } from "../Worker.js"; import { testWorkflow } from "./workflows/test-workflow.js"; import { DurableFunctionsWorkflowHistoryStore, MemoryWorkflowHistoryStore, type WorkflowInstanceHeader } from "../stores/index.js"; import { sleep } from "../sleep.js"; +import { throwErrorWorkflow } from "./workflows/throw-error-workflow.js"; test.before(async () => { const worker = Worker.getInstance(); @@ -91,3 +92,26 @@ void test("Workflow store, getInstances options", async (t) => { assert.equal(thirty.instances.length, 30); assert.equal(all.length, 100); }); + + +void test("Workflow store, getInstances error", async (t) => { + // Arrange + const worker = Worker.getInstance(); + + // Act + let workflowId : string | undefined; + try { + const handle = await worker.start(throwErrorWorkflow); + workflowId = handle.workflowId; + await handle.result(); + assert.fail(); + } catch { + // Ignore, expected to throw + } + + // Assert + const instances = await worker.store.getInstances(); + const instance = instances.instances.find(wi => wi.instanceId === workflowId); + assert.ok(instance, "Expected instance to be found."); + assert.ok(instance.error, "Expected error to be true."); +}); \ No newline at end of file