Async Job Queue Example Specification

Goal

Create a small CLI example that makes Async::Redis concurrency visible without requiring a web framework or extra UI.

The example should prove three things:

Location

User Story

As a new Async::Redis user, I can run one command and see jobs being queued, claimed by workers, processed concurrently, and reported by a heartbeat while the process remains responsive.

Runtime Behavior

The app should:

Default values:

Async Design

Use separate Redis connections for roles that can block independently:

Workers must use BLPOP so the example demonstrates a real Redis blocking operation. Each worker connection may sit inside BLPOP without preventing the producer, heartbeat, or other workers from making progress.

Workers should simulate job processing with Future::IO->sleep($delay) rather than CPU work. The point is event-loop concurrency, not parallel CPU execution.

The app should coordinate all tasks with futures, for example:

Queue Semantics

Startup:

Worker loop:

Shutdown:

The stop sentinel should be a value that cannot collide with generated job names, for example __async_job_queue_stop__.

Output Requirements

Output must be human-readable and timestamped relative to process start.

It should make queueing and async behavior obvious. Example shape:

[ 0.00s] queued 10 jobs
[ 0.01s] worker-1 started job-1
[ 0.01s] worker-2 started job-2
[ 0.25s] heartbeat queue=8 in_flight=2 processed=0
[ 1.51s] worker-1 finished job-1
[ 1.51s] worker-1 started job-3
[ 1.51s] worker-2 finished job-2
[ 1.51s] worker-2 started job-4
[ 1.75s] heartbeat queue=6 in_flight=2 processed=2
[ 7.55s] done processed=10 workers=2 elapsed=7.55s sequential_about=15.00s

The README should explain that the heartbeat lines are the key proof: the process continues running other async work while workers are blocked in Redis or waiting on simulated work.

CLI

Keep the first version simple, but allow the demo to be tweaked:

examples/async-job-queue/app.pl [options]

Options:
  --jobs N       number of jobs to enqueue, default 10
  --workers N    number of workers, default 2
  --delay SEC    simulated seconds per job, default 1.5
  --help         show usage

Validation:

Dependencies

Use only modules already required by the distribution or Perl core where possible:

Do not require PAGI, AnyEvent, IO::Async-specific setup, or a web server.

Documentation Requirements

examples/async-job-queue/README.md should include:

examples/README.md should add an async-job-queue section with a short description and one run command.

Test And Verification Plan

Manual smoke test:

perlbrew use perl-5.40.0@default
docker compose -f examples/docker-compose.yml up -d
REDIS_HOST=localhost perl examples/async-job-queue/app.pl --jobs 6 --workers 2 --delay 0.2

Expected:

Automated lightweight check, if added later:

Non-Goals

This is an educational example, not a production queue implementation.