Duty

Durable TypeScript tasks for everyone

Durability platform that makes code run to completion.
With automated retries, backoff and observability built-in.
No external dependencies - use your existing storage layer & infra.

Get started immediately
$npm i --save @duty/core
import { worker } from "@duty/core"

const db = new PrismaClient() 

const duty = await worker({ storage: prismaAdapter(db) })

const activities = {
    "generateTextEmbedding": async (params: { documentId: string }) => {
        const document = await db.documents.findOne(params.documentId)
        const embedding = await openai.embed(document.text)
        await db.embeddings.create({ data: { documentId: document.id, embedding } })
    }
}

const embedDocumentsTask = duty.task({
      name: 'embed-documents',
      activities,
      run: async (context, params: { documentIds: string[] }) => {
          for (let documentId of params.documentIds) {
              await context.activities.generateTextEmbedding({ documentId })
          }
      }
})

await embedDocumentsTask.run({ documentIds: ['document-1', 'document-2', '...'] })

This example shows a durable way to fetch embeddings in bulk from OpenAI.
Duty uses your existing Prisma database setup as backing storage (other adapters available).
Should the task error due to e.g. API rate limiting, the task retries automatically.
Activities are cached by default, so each activity runs at most once for a given set of params.

Uses your Database

No external dependencies - Duty works with your existing database (Postgres, Redis, ...) and ORM (Prisma, Kysely, ...) as backing storage.

Powerful Dashboard

Your durability command center, Duty Admin gives a historical view of tasks, activities and event states.

open source

Fully Open Source

Duty is built in public by people who use it daily. We welcome your feedback and contributions.

Unleashes Productivity

Write code without headaches. Duty does what's needed to make it run to completion.

Duty Cloud for extreme reliability

Large scale with maximum reliability.
Duty Cloud runks your tasks for you so you can focus on writing code.

Coming Soon

Start building durable tasks today!

$npm i --save @duty/core