Skip to content

Commit

Permalink
fix: check runtime status in durable functions store getInstances
Browse files Browse the repository at this point in the history
  • Loading branch information
allanhvam committed Aug 13, 2024
1 parent f445bda commit 31d0ef5
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
9 changes: 8 additions & 1 deletion src/stores/DurableFunctionsWorkflowHistoryStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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);
Expand Down
24 changes: 24 additions & 0 deletions src/tests/store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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.");
});

0 comments on commit 31d0ef5

Please sign in to comment.