Quick Start: Pull (Worker)
Your worker long-polls Chronos for jobs, runs your handler, and reports the result. You control the compute.
Prerequisites
Section titled “Prerequisites”- Node.js 20 or later
- A Chronos account (sign up free)
- An API key (create one in the dashboard under Settings → API Keys)
-
Install the SDK
Terminal window pnpm add @chronos.sh/sdkTerminal window npm install @chronos.sh/sdkTerminal window yarn add @chronos.sh/sdk -
Write your handler
worker.ts import { Chronos } from '@chronos.sh/sdk';const chronos = new Chronos({apiKey: process.env.CHRONOS_API_KEY!,});chronos.worker.handle('hello', async (ctx) => {console.log(`Job ${ctx.jobId} running (attempt ${ctx.attempt})`);return { ok: true };});await chronos.worker.start();The handler name
"hello"is the routing key. Chronos uses it to match jobs to the right function. -
Start the worker
Terminal window CHRONOS_API_KEY=chrns_your_api_key pnpm dlx tsx worker.tsTerminal window CHRONOS_API_KEY=chrns_your_api_key npx tsx worker.tsTerminal window CHRONOS_API_KEY=chrns_your_api_key yarn dlx tsx worker.tsThe worker connects to Chronos and waits for jobs.
-
Create a job
In a second terminal, create a one-off job:
Terminal window curl -X POST https://api.chronos.sh/v1/jobs \-H "Authorization: Bearer chrns_your_api_key" \-H "Content-Type: application/json" \-d '{"name": "My first job","handler": "hello"}'Your running worker claims the job and runs the handler. You should see:
Job a8f3e2b1-... running (attempt 1)
What just happened
Section titled “What just happened”- You created a one-off job via the API
- Your worker long-polled Chronos and claimed it
- The handler ran and returned a result
- Chronos recorded the execution as
completed
If the handler had thrown an error, Chronos would have retried up to 3 times with exponential backoff.
Make it recurring
Section titled “Make it recurring”Create a schedule and your worker picks up jobs automatically:
curl -X POST https://api.chronos.sh/v1/schedules \ -H "Authorization: Bearer chrns_your_api_key" \ -H "Content-Type: application/json" \ -d '{ "name": "Hello every 10 minutes", "handler": "hello", "interval": { "value": 10, "unit": "minute" } }'Your running worker now receives a new job every 10 minutes. To stop it, archive the schedule:
curl -X POST https://api.chronos.sh/v1/schedules/SCHEDULE_ID/archive \ -H "Authorization: Bearer chrns_your_api_key"Next steps
Section titled “Next steps” Worker Setup Prod config: graceful shutdown, multiple handlers, error handling
Push Delivery Switch to HTTP push delivery
API Reference Full endpoint documentation