Async Job Queue Example Implementation Plan

Goal

Implement examples/async-job-queue/ from examples/async-job-queue/SPEC.md: a small CLI demo that visibly proves Async::Redis can run a Redis-backed job queue concurrently in one Perl process.

The demo should show:

Constraints

Files

Create:

Modify:

Existing spec:

Step 1: Preflight And Scope Check

At the start, confirm the current branch and dirty tree:

git status --short --branch

Review:

No code changes in this step.

Step 2: Add CLI Skeleton

Create examples/async-job-queue/app.pl with:

Verification:

perlbrew use perl-5.40.0@default
perl -c examples/async-job-queue/app.pl
perl examples/async-job-queue/app.pl --help
perl examples/async-job-queue/app.pl --jobs 0

Expected:

Review after step:

Step 3: Add Redis Connections And Startup Cleanup

Add:

For this step, main() should connect a controller client, clean demo keys, print a short success line, disconnect, and exit.

Verification:

perlbrew use perl-5.40.0@default
perl -c examples/async-job-queue/app.pl
REDIS_HOST=localhost perl examples/async-job-queue/app.pl --jobs 1 --workers 1 --delay 0.1

Expected:

Review after step:

Step 4: Implement Producer Burst

Add:

For this step, enqueue jobs and then clean them up before exit so repeated manual runs do not leave queue entries behind.

Verification:

perlbrew use perl-5.40.0@default
perl -c examples/async-job-queue/app.pl
REDIS_HOST=localhost perl examples/async-job-queue/app.pl --jobs 3 --workers 1 --delay 0.1

Expected:

Review after step:

Step 5: Implement One Worker Loop

Add:

Initially wire one worker and have the controller push one sentinel after all jobs are processed.

Verification:

perlbrew use perl-5.40.0@default
perl -c examples/async-job-queue/app.pl
REDIS_HOST=localhost perl examples/async-job-queue/app.pl --jobs 2 --workers 1 --delay 0.1

Expected:

Review after step:

Step 6: Run Multiple Workers Concurrently

Change main() to start $workers worker futures concurrently and wait for them all to finish.

Shutdown should push one sentinel per worker after all real jobs are processed.

Verification:

perlbrew use perl-5.40.0@default
perl -c examples/async-job-queue/app.pl
REDIS_HOST=localhost perl examples/async-job-queue/app.pl --jobs 4 --workers 2 --delay 0.2

Expected:

Review after step:

Step 7: Add Heartbeat Task

Add:

Verification:

perlbrew use perl-5.40.0@default
perl -c examples/async-job-queue/app.pl
REDIS_HOST=localhost perl examples/async-job-queue/app.pl --jobs 6 --workers 2 --delay 0.2

Expected:

Review after step:

Step 8: Final Summary And Cleanup

Add final summary:

Add final cleanup:

Verification:

perlbrew use perl-5.40.0@default
perl -c examples/async-job-queue/app.pl
REDIS_HOST=localhost perl examples/async-job-queue/app.pl --jobs 10 --workers 2 --delay 0.1

Expected:

Review after step:

Step 9: Add README

Create examples/async-job-queue/README.md with:

Verification:

perlbrew use perl-5.40.0@default
perl -c examples/async-job-queue/app.pl

Manual review:

Step 10: Update Examples Index

Modify examples/README.md to add an async-job-queue section.

Include:

Verification:

perlbrew use perl-5.40.0@default
perl -c examples/async-job-queue/app.pl

Manual review:

Step 11: End-To-End Smoke Test

Run the canonical smoke test:

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

Expected:

If Redis access is blocked by the sandbox, rerun with escalation rather than changing the app.

Review after step:

Run focused tests for areas touched by the example:

perlbrew use perl-5.40.0@default
prove -lr t/70-blocking t/01-unit

Expected:

Review after step:

Step 13: Final Review

Before considering the work complete:

git status --short --branch
git diff -- examples/async-job-queue examples/README.md

Review:

Optional Follow-Up

If a future automated example test is desired, add a lightweight test that runs:

REDIS_HOST=localhost perl examples/async-job-queue/app.pl --jobs 4 --workers 2 --delay 0.05

and asserts output contains:

Do not add this unless the project wants Redis-backed example tests in the normal test suite.