graphile-worker-orchid
TypeScript icon, indicating that this package has built-in type declarations

1.2.0 • Public • Published

graphile-worker-orchid

Use graphile-worker with orchid-orm, including support for transactions.

Install

pnpm add graphile-worker-orchid

Use

Create worker utils:

import { makeWorkerUtils } from "graphile-worker-orchid"
import { orchidORM } from "orchid-orm"

const db = orchidORM({ databaseURL: "..." }, {
  // table definitions
})

const {
  addJob,
  removeJob,
  waitJob,
} = makeWorkerUtils(db)

addJob

Add job with job name, params, and possibly options:

await addJob("test", { foo: 123 }, {
  jobKey: "testing",
})

This also works in transaction:

await db.$transaction(async () => {
  const user = await db.user.select("id", "name", "email").create(userInput)
  // The job will only by added when and if the transaction commits.
  await addJob("sendRegistrationEmail", { user })
})

removeJob

Remove job by job key:

await removeJob("testing")

waitJob

Wait for a job to complete by its job ID:

const job = await addJob("test", { foo: 123 })

// Will throw if the job fails (reaches max retry attempts).
await waitJob(job.id)

The function waits by simple polling. You can override the polling interval with:

await waitJob(job.id, {
  pollInterval: 200, // Default is 1000 ms
})

Readme

Keywords

none

Package Sidebar

Install

npm i graphile-worker-orchid

Weekly Downloads

8

Version

1.2.0

License

MIT

Unpacked Size

17.6 kB

Total Files

11

Last publish

Collaborators

  • ilyasemenov