Getting started
Introduction
Bok Joy runs your Node and Python functions as durable tasks, with retries, waits that survive restarts, and burst machines when your own workers are full.
You write a task as an ordinary exported function. Your backend triggers it with a payload. Bok Joy records the run in Postgres, decides where each attempt runs, retries it when it fails, and keeps the result, the logs and every attempt.
onboarding.mjs
import {sendEmail} from './mailer.mjs'; const DAY = 24 * 60 * 60 * 1000; // A task. It retries up to max_attempts, and// ctx.idempotencyKey stays the same on every attempt.export async function send({email, template}, ctx) { await sendEmail(email, template, ctx.idempotencyKey); return {sent: true};} // A workflow. Each awaited step is recorded: after a restart// it resumes where it stopped, and a wait holds no worker.export async function onboarding({email}, ctx) { const mail = (template) => ctx.callTask('email.send', {email, template}, template); await mail('welcome'); const reply = await ctx.waitEvent('activated', 3 * DAY); if (reply.timed_out) await mail('nudge'); return {activated: !reply.timed_out};}from mailer import send_email DAY = 24 * 60 * 60 * 1000 # A task. It retries up to max_attempts, and# ctx.idempotency_key stays the same on every attempt.def send(input, ctx): email, template = input["email"], input["template"] send_email(email, template, ctx.idempotency_key) return {"sent": True} # A workflow. Each awaited step is recorded: after a restart# it resumes where it stopped, and a wait holds no worker.async def onboarding(input, ctx): email = input["email"] async def mail(template): payload = {"email": email, "template": template} await ctx.call_task("email.send", payload, template) await mail("welcome") reply = await ctx.wait_event("activated", 3 * DAY) if reply["timed_out"]: await mail("nudge") return {"activated": not reply["timed_out"]}What you build with it#
- Tasks. A task is a function that takes a payload and returns JSON. A failed attempt retries, up to the task's
max_attempts. - Workflows. A workflow is a function whose awaited steps are recorded. It can call other tasks, sleep and wait for events for up to 7 days, and a restart resumes it after the last finished step.
- Triggers from any backend. Your app starts runs with
tasks.trigger,tasks.batchTriggerandtasks.triggerAndWaitfrom the Node or Python SDK, holding one environment API key. - Schedules. A task can run on a cron in a time zone, declared with the task or created from your backend. See Schedules.
How a run flows#
- Deploy. The deploy command builds one pinned image per runtime with your locked npm or PyPI dependencies, and can make it current in an environment you name, such as
prod. - Trigger. Your backend calls
tasks.triggerwith the task ID, a payload and an idempotency key. The API key picks the environment, so the run uses that environment's current deployment and variables. Sending the same key again returns the same run. - Place. Once the run's queue has room, Bok Joy offers it to your private workers first. When none can take it and its placement allows, it starts a burst machine on Bok Joy's cloud, within hard caps.
- Run and record. A worker leases one attempt at a time. Each attempt's status, logs and timing stay with the run. A workflow suspends at each step and resumes in a new attempt when the step finishes.
- Read the result. Your app reads the run with
runs.retrieve, waits for it withruns.poll, or follows it live withruns.subscribe.
A run stays pinned to the deployment it started on. Deploying new code never changes a run that is already going.
Key terms#
| Term | Meaning |
|---|---|
| Task | An exported function registered in a manifest under an ID such as email.send. Its kind is task or workflow. |
| Run | One execution of a task for one payload. It has a status, an output or an error, and its attempts. |
| Attempt | One try at a run on one worker. A task retries in a new attempt; a workflow resumes in a new attempt after each step. |
| Deployment | A content-addressed bundle of your task code and its pinned images. Runs keep the deployment they started on. |
| Project | One app in your organization, with its own environments. |
| Environment | dev, staging, prod or preview/<branch>, in a project. Each has its own current deployment, variables and API keys. |
| Worker | A process that claims attempts and runs them: one of your machines, or a burst machine on Bok Joy's cloud. |
| Control plane | The Bok Joy server. It stores runs in Postgres, serves the HTTP API and schedules attempts. The hosted alpha's is at https://api.bokjoy.dev. |
Where to go next#
- Quickstart: define a task and a workflow, run them locally and trigger them from an app.
- Tasks and Workflows: how handlers behave, retry and resume.
- Set up the client: call Bok Joy from your own backend.
- Coming from Trigger.dev: what carries over and what changes.
- Next.js: a starter app that triggers runs from Server Actions and shows them live.