baobab/docs/REDIS_QUEUES_GUIDE.md
Maxime Van Hees 0ebda7c1aa Updates
2025-08-14 14:14:34 +02:00

8.4 KiB
Raw Blame History

Redis Queues Guide: Who Pushes Where, When, and How to Inspect

This guide documents the canonical queues used in the project, explains which component pushes to which queue at each step, and provides redis-cli commands to inspect state during development.

Canonical keys

  1. Who pushes where

A. Supervisor: creating, starting, and running jobs

B. Terminal UI: quick dispatch from the actor TUI

C. Actors: consuming and completing work

  1. End-to-end flows and the queues involved

Flow A: Two-step (create + start) with Supervisor

  • Code path:
  • Keys touched:
    • hero:job:{job_id} (created)
    • hero:q:work:type:{script_type} (LPUSH job_id)
  • Expected actor behavior:
  • How to inspect with redis-cli:
    • FLUSHALL (fresh dev) then run create and start
    • Verify job hash:
      • HGETALL hero:job:{job_id}
    • Verify queue length before consumption:
      • LLEN hero:q:work:type:osis
    • See pending items:
      • LRANGE hero:q:work:type:osis 0 -1
    • After actor runs, verify result in job hash:
      • HGET hero:job:{job_id} status
      • HGET hero:job:{job_id} output

Flow B: One-shot (run and await result) with Supervisor

  • Code path:
  • Keys touched:
    • hero:job:{job_id}
    • hero:q:work:type:{script_type}
    • hero:q:reply:{job_id} (only if an actor uses reply queues)
  • How to inspect with redis-cli:
    • While waiting:
      • LLEN hero:q:work:type:osis
      • HGET hero:job:{job_id} status
    • If an actor uses reply queues (optional):
      • LLEN hero:q:reply:{job_id}
      • LRANGE hero:q:reply:{job_id} 0 -1
    • After completion:
      • HGET hero:job:{job_id} output

Flow C: Dispatch from the Actor TUI (manual testing)

  • Code path:
  • Keys touched:
    • hero:job:{job_id}
    • hero:q:work:type:{script_type}
  • How to inspect with redis-cli:
    • List all work queues:
      • KEYS hero:q:work:type:*
    • Show items in a specific type queue:
      • LRANGE hero:q:work:type:osis 0 -1
    • Read one pending job:
      • HGETALL hero:job:{job_id}
    • After actor runs:
      • HGET hero:job:{job_id} status
      • HGET hero:job:{job_id} output
  1. Example redis-cli sequences

A. Basic OSIS job lifecycle (two-step)

  • Prepare
    • FLUSHALL
  • Create and start (via code or supervisor-cli)
  • Inspect queue and job
    • KEYS hero:q:work:type:*
    • LLEN hero:q:work:type:osis
    • LRANGE hero:q:work:type:osis 0 -1
    • HGETALL hero:job:{job_id}
  • After actor consumes the job:
    • HGET hero:job:{job_id} status → finished
    • HGET hero:job:{job_id} output → script result
    • LLEN hero:q:work:type:osis → likely 0 if all consumed

B. One-shot run-and-wait (hash-only actor)

  • Prepare
    • FLUSHALL
  • Submit via run_job_and_await_result()
  • While supervisor waits:
    • HGET hero:job:{job_id} status → started/finished
    • (Optional) LLEN hero:q:reply:{job_id} → typically 0 if actor doesnt use reply queues
  • When done:
    • HGET hero:job:{job_id} output → result

C. Listing and cleanup helpers

  • List jobs
    • KEYS hero:job:*
  • Show a specific job
    • HGETALL hero:job:{job_id}
  • Clear all keys (dev only)
    • FLUSHALL
  1. Where the queue names are computed in code
  1. Quick checklist for debugging
  • Nothing consumes from the type queue
    • Is at least one actor process running that BLPOPs hero:q:work:type:{script_type}?
    • LLEN hero:q:work:type:{script_type} shows > 0 means unconsumed backlog
  • Job “Dispatched” but never “Finished”
    • HGET hero:job:{job_id} status
    • Actor logs: check for script errors and verify it is connected to the same Redis
  • “run-and-wait” timeout
    • Hash-only actors dont push to reply queues; the supervisor will still return once it sees hero:job:{job_id}.output set by rust.Job::set_result()
  • Mixed types:
    • Verify you targeted the correct type queue (e.g., osis vs sal): LLEN hero:q:work:type:osis, hero:q:work:type:sal
  1. Canonical patterns to remember
  • To dispatch a job:
    • LPUSH hero:q:work:type:{script_type} {job_id}
  • To read job data:
    • HGETALL hero:job:{job_id}
  • To wait for output (optional reply model):
    • BLPOP hero:q:reply:{job_id} {timeout_secs}
  • To verify system state:
    • KEYS hero:q:*
    • KEYS hero:job:*

This guide reflects the canonical scheme implemented in: