Skip to content

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.

On this page

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.

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};}

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.batchTrigger and tasks.triggerAndWait from 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#

  1. 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.
  2. Trigger. Your backend calls tasks.trigger with 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.
  3. 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.
  4. 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.
  5. Read the result. Your app reads the run with runs.retrieve, waits for it with runs.poll, or follows it live with runs.subscribe.

A run stays pinned to the deployment it started on. Deploying new code never changes a run that is already going.

Key terms#

TermMeaning
TaskAn exported function registered in a manifest under an ID such as email.send. Its kind is task or workflow.
RunOne execution of a task for one payload. It has a status, an output or an error, and its attempts.
AttemptOne try at a run on one worker. A task retries in a new attempt; a workflow resumes in a new attempt after each step.
DeploymentA content-addressed bundle of your task code and its pinned images. Runs keep the deployment they started on.
ProjectOne app in your organization, with its own environments.
Environmentdev, staging, prod or preview/<branch>, in a project. Each has its own current deployment, variables and API keys.
WorkerA process that claims attempts and runs them: one of your machines, or a burst machine on Bok Joy's cloud.
Control planeThe 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#