Skip to content

Simple type-safe queue worker with durable execution based on BullMQ.

License

Notifications You must be signed in to change notification settings

falcondev-oss/workflow

Repository files navigation

@falcondev-oss/workflow

Simple type-safe queue worker with durable execution based on BullMQ.

Installation

npm install @falcondev-oss/workflow

Usage

const workflow = new Workflow({
  id: 'example-workflow',
  input: z.object({
    timezone: z.string().default('UTC'),
    name: z.string(),
  }),
  async run({ input, step }) {
    await step.do('send welcome', () => {
      console.log(`Welcome, ${input.name}! Timezone: ${input.timezone}`)
    })

    await step.wait('wait a lil', 60_000)

    const isEngaged = await step.do('check engagement', () => {
      return Math.random() > 0.5
    })

    if (!isEngaged) return { engagementLevel: 'low' }

    await step.do('send tips', () => {
      console.log(`Here are some tips to get started, ${input.name}!`)
    })

    await step.wait('wait feedback', 3000)

    await step.do('send survey', () => {
      console.log(`Hi ${input.name}, please take our survey!`)
    })

    return {
      engagementLevel: 'high',
    }
  },
})

// Start worker
await workflow.work()

// Run workflow
const job = await workflow.run({
  name: 'John Doe',
  timezone: 'America/New_York',
})

// Wait for completion
const result = await job.wait()
console.log(result.engagementLevel)

Inspiration

About

Simple type-safe queue worker with durable execution based on BullMQ.

Topics

Resources

License

Stars

Watchers

Forks

Contributors 2

  •  
  •