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.
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.
No external dependencies - Duty works with your existing database (Postgres, Redis, ...) and ORM (Prisma, Kysely, ...) as backing storage.
Your durability command center, Duty Admin gives a historical view of tasks, activities and event states.
Duty is built in public by people who use it daily. We welcome your feedback and contributions.
Write code without headaches. Duty does what's needed to make it run to completion.
Large scale with maximum reliability.
Duty Cloud runks your tasks for you so you can focus on writing code.