mirror of
https://github.com/vercel/workflow.git
synced 2026-09-14 19:59:43 +08:00
4ca9a3edbd
build durable, resilient, and observable workflows. Co-authored-by: Nathan Rajlich <n@n8.io> Co-authored-by: Pranay Prakash <pranay.gp@gmail.com> Co-authored-by: Adrian <me@adriandlam.com> Co-authored-by: JJ Kasper <jj@jjsweb.site> Co-authored-by: Vercel Release Bot <88769842+vercel-release-bot@users.noreply.github.com> Co-authored-by: Peter Wielander <mittgfu@gmail.com> Co-authored-by: Hayden Bleasel <hello@haydenbleasel.com> Co-authored-by: Gal Schlezinger <gal@spitfire.co.il> Co-authored-by: Manuel Muñoz Solera <mamuso@mamuso.net> Co-authored-by: Garrett <garrett.tolbert@vercel.com> Co-authored-by: Lars Grammel <lars.grammel@gmail.com> Co-authored-by: Pooya Parsa <pyapar@gmail.com> Co-authored-by: Tom Dale <tom@tomdale.net> Co-authored-by: Vishal Yathish <135551666+visyat@users.noreply.github.com> Co-authored-by: josh <144584931+dancer@users.noreply.github.com>
31 lines
680 B
TypeScript
31 lines
680 B
TypeScript
import { FatalError } from 'workflow';
|
|
|
|
async function add(a: number, b: number): Promise<number> {
|
|
'use step';
|
|
|
|
// Mimic a retryable error 50% of the time
|
|
if (Math.random() < 0.5) {
|
|
throw new Error('Retryable error');
|
|
}
|
|
|
|
// Mimic a 5% chance of the workflow actually failing
|
|
if (Math.random() < 0.05) {
|
|
throw new FatalError("We're cooked yo!");
|
|
}
|
|
|
|
return a + b;
|
|
}
|
|
|
|
export async function simple(i: number) {
|
|
'use workflow';
|
|
console.log('Simple workflow started');
|
|
|
|
const a = await add(i, 7);
|
|
console.log('Workflow step 1 completed - Result:', a);
|
|
|
|
const b = await add(a, 8);
|
|
console.log('Simple workflow completed. Result:', b);
|
|
|
|
return b;
|
|
}
|