Configuration

Create a tasks.yaml file in your project root to define your jobs:

tasks.yaml
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: 120

Configuration Options

OptionTypeDescription
descriptionstringHuman-readable description of what the job does
schedulestringCron expression defining when the job runs
filestringPath to the TypeScript file containing the job
timeoutnumberMaximum 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

PatternMeaning
* * * * *Every minute
*/5 * * * *Every 5 minutes
0 * * * *Every hour
0 0 * * *Daily at midnight
0 0 * * 0Weekly 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
// 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:

terminal
captain ./tasks.yaml

Command Line Options

OptionDescription
--run <task>Run a specific task immediately, bypassing the schedule
--dry-runShow what tasks would run without executing them
--verboseEnable verbose logging output
--helpDisplay help information

Examples

Run a specific task immediately

terminal
captain ./tasks.yaml --run batch_processor

Preview scheduled tasks

terminal
captain ./tasks.yaml --dry-run

Run with verbose logging

terminal
captain ./tasks.yaml --verbose
NoEgo

© 2025 NoEgo. All rights reserved.