-
Notifications
You must be signed in to change notification settings - Fork 11
Open
Description
It's not clear reading from the doc, it seems like workflowids are scoped inside appversion as idempotent keys, but in reality workflowId are globally idempotent, this is very useful knowledge because now we can also use DBOS workflow to cache expensive results
import { describe, expect, it } from "vitest";
import { PostgreSqlContainer } from "@testcontainers/postgresql";
import { DBOS } from "@dbos-inc/dbos-sdk";
async function getRandomNumbers(input: number) {
return Math.floor(Math.random() * 1000000);
}
const workflow = DBOS.registerWorkflow(getRandomNumbers);
describe("Using workflows as cache", () => {
it("should cache result between different version of workflows", async () => {
expect(await getRandomNumbers(1)).to.not.equal(await getRandomNumbers(1));
await using container = await new PostgreSqlContainer(
"postgres:15-alpine",
).start();
DBOS.setConfig({
name: "test",
systemDatabaseUrl: container.getConnectionUri(),
applicationVersion: "111",
});
await DBOS.launch();
const firstRun = await DBOS.startWorkflow(workflow, {
workflowID: "1",
})(1);
const firstResult = await firstRun.getResult();
await DBOS.shutdown();
DBOS.setConfig({
name: "test",
systemDatabaseUrl: container.getConnectionUri(),
applicationVersion: "222",
});
await DBOS.launch();
const secondRun = await DBOS.startWorkflow(workflow, {
workflowID: "1",
})(1);
const secondResult = await secondRun.getResult();
await DBOS.shutdown();
expect(firstResult).toEqual(secondResult);
});
});
Metadata
Metadata
Assignees
Labels
No labels