This is a mini Temporal-like workflow engine for TypeScript implemented with pluggable backends for AWS (CloudFlare coming soon).
Caution
The code was build in a day and is not fully tested. The e2e example works, but there may be bugs.
- See the example/index.ts file for the Lambda Function entrypoint.
- See the example/workflow.ts file for the workflow implementation.
- See the sst.config.ts file for infrastructure configuration.
const engine = new WorkflowEngine("WorkflowEngine", {
worker: "example/index.execute",
orchestrator: "example/index.orchestrate",
});
import { workflow } from "mini-workflow";
// a workflow is implemented as a simple function accepting context and arbitrary parameters
export const uploadObjectWorkflow = workflow(
"uploadObjectWorkflow",
async (ctx, key: string, data: string) => {
// ctx.sleep will sleep (pause the workflow) for 1 second
await ctx.sleep(1);
// ctx.task will asynchronously (and durably, with at-least-once delivery) run the provided function in the worker Lambda Function
await ctx.task(async () => {
await s3Client.send(
new PutObjectCommand({
Bucket: bucketName,
Key: key,
Body: data,
})
);
});
const response = await ctx.task(async () => {
const response = await s3Client.send(
new GetObjectCommand({
Bucket: bucketName,
Key: key,
})
);
return response.Body?.transformToString() ?? "";
});
return response;
}
);
Replay events in a Javascript Debug Terminal to step-through debug a workflow that ran in AWS (or is still running).
npx tsx ./src/cli.ts replay \
--main ./example/workflow.ts \
--bucket-name <bucket-name> \
--execution-id <execution-id>