Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: check runtime status in durable functions store getInstances #17

Merged
merged 1 commit into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.");
});