Configuration
Create a tasks.yaml file
in your project root to define your jobs:
tasks:
batch_processor:
description: "Process batch items and check running batches"
schedule: "* * * * *"
file: "./server/jobs/batch_processor.ts"
timeout: 30
billing_consolidation:
description: "Consolidate polling logs into billing sessions"
schedule: "*/5 * * * *"
file: "./server/jobs/billing_consolidation.ts"
timeout: 120Configuration Options
| Option | Type | Description |
|---|---|---|
| description | string | Human-readable description of what the job does |
| schedule | string | Cron expression defining when the job runs |
| file | string | Path to the TypeScript file containing the job |
| timeout | number | Maximum execution time in seconds before the job is killed |
Schedule Syntax
Captain uses standard cron syntax for scheduling. The format is:
* * * * *
│ │ │ │ │
│ │ │ │ └── Day of week (0-7, 0 or 7 is Sunday)
│ │ │ └──── Month (1-12)
│ │ └────── Day of month (1-31)
│ └──────── Hour (0-23)
└────────── Minute (0-59)Common Examples
| Pattern | Meaning |
|---|---|
| * * * * * | Every minute |
| */5 * * * * | Every 5 minutes |
| 0 * * * * | Every hour |
| 0 0 * * * | Daily at midnight |
| 0 0 * * 0 | Weekly on Sunday |
| 0 0 1 * * | Monthly on the 1st |
Writing Job Files
Each job file should export a default async function. Captain will call this function when the job is scheduled to run:
// server/jobs/batch_processor.ts
export default async function batchProcessor() {
console.log("Processing batch items...");
// Your job logic here
const items = await fetchPendingItems();
for (const item of items) {
await processItem(item);
}
console.log("Batch processing complete");
}Important
Jobs should be idempotent and handle failures gracefully. If a job fails, Captain will not retry automatically - you should implement retry logic within your job if needed.
Command Line Usage
Run Captain with the path to your tasks configuration file:
captain ./tasks.yamlCommand Line Options
| Option | Description |
|---|---|
| --run <task> | Run a specific task immediately, bypassing the schedule |
| --dry-run | Show what tasks would run without executing them |
| --verbose | Enable verbose logging output |
| --help | Display help information |
Examples
Run a specific task immediately
captain ./tasks.yaml --run batch_processorPreview scheduled tasks
captain ./tasks.yaml --dry-runRun with verbose logging
captain ./tasks.yaml --verbose