@zwolf/job
TypeScript icon, indicating that this package has built-in type declarations

2.2.0 • Public • Published

@zwolf/job

Keep track of pending/failed jobs

import { jobMiddleware, createEventStore } from '@zwolf/job'

type Payload = {
  userId: string
}

const paymentStore = createEventStore<Payload>((payload) => {
  const { userId } = payload
  return `payment-store-${userId}`
})

const handlePayment = jobMiddleware(paymentStore)((message, dispatch) => {
  const { fromAccountId, toAccountId, amount } = message.payload
  await makePayment({ fromAccountId, toAccountId, amount })
})

const event = await paymentStore.get({ userId: 'george' })
await dispatchOnNextSuccess(event.id, {
  type: 'notify-user',
  payload: {
    userId: 'george',
    message: 'Payment was successful'
  }
})

Readme

Keywords

none

Package Sidebar

Install

npm i @zwolf/job

Weekly Downloads

0

Version

2.2.0

License

MIT

Unpacked Size

14 kB

Total Files

9

Last publish

Collaborators

  • stayradiated