eventual
eventual copied to clipboard
Heartbeat Checkpoint
workflow(() => {
const act = act1();
act.onHeartbeat(async ({ i: 100 }) => {
await reportProgress(i);
});
});
const reportProceess = activity(...);
const act1 = activity<{ result: string }, { i: 100 } | undefined>({
heartbeat: { seconds: 20 },
timeout: { seconds: 160 }
}, (context: Context): { result: string } | AsyncToken => {
...doSomeWork...
await sendToQueue({ token: context.activity.token, start: context.checkpoint });
// should this be on the context to be typed?
await sendHeartbeat();
return makeAsync();
})
// lambda function consuming the queue
const workflowClient = new WorkflowClient();
export const handler = async (event) => {
Promise.all(event.Records.map(async (record) => {
const payload = JSON.parse(record.body);
const items = [...];
const start = event.start ?? 0;
for(const i of items.slice()) {
// some long process
await workflowClient.heartbeatActivity<typeof act1>(
payload.token,
{ i }
);
}
// complete the activity with a payload
await workflowClient.completeActivity<typeof act1>(
payload.token,
{ result: "done"}
);
}));
}
https://github.com/functionless/eventual/issues/60