← All lessons/Automation
37
Automation

Cron Jobs

Schedule recurring jobs that run inside SapixDB — no external scheduler required.

Prerequisite: Lesson 5 complete

What you'll learn

  • POST /v1/agents/:id/crons — name, schedule (5-field cron), action
  • action types: write to an agent, call a webhook
  • GET /v1/agents/:id/crons — list crons
  • DELETE /v1/agents/:id/crons/:name — remove
  • Standard cron expressions: * * * * * (every minute) to 0 0 1 * * (monthly)
Challenge

Create a cron that writes a heartbeat record every minute. Wait 3 minutes. Verify 3 records were written.

Interactive Walkthrough

What you'll learn

Schedule recurring jobs that run inside SapixDB — no external scheduler required.

Create a cron job

curl -s -X POST http://localhost:7475/v1/agents/jobs/crons \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer spx_root_YOUR_ROOT_KEY" \
  -d '{
    "name":       "daily-report",
    "schedule":   "0 9 * * *",
    "action":     {
      "type":     "write",
      "agent_id": "reports",
      "payload":  {"type": "daily_summary", "generated_by": "cron"}
    }
  }' | python3 -m json.tool

List crons

curl -s http://localhost:7475/v1/agents/jobs/crons \
  -H "Authorization: Bearer spx_root_YOUR_ROOT_KEY" \
  | python3 -m json.tool

Delete a cron

curl -s -X DELETE http://localhost:7475/v1/agents/jobs/crons/daily-report \
  -H "Authorization: Bearer spx_root_YOUR_ROOT_KEY"

Cron schedule format (standard 5-field)

FieldValues
minute0–59
hour0–23
day of month1–31
month1–12
day of week0–7 (0=Sunday)

Examples: - * * * * * — every minute - 0 * * * * — every hour - 0 9 * * 1 — every Monday at 09:00 - 0 0 1 * * — first day of every month

Challenge

Create a cron that writes a heartbeat record to a heartbeats agent every minute. Wait 3 minutes. Verify 3 records were written.

---

← Previous
Lesson 36: Key Rotation
Next →
Lesson 38: Triggers