Download the PHP package deverity/spawn-queue without Composer
On this page you can find all versions of the php package deverity/spawn-queue. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package spawn-queue
SpawnQueue — CakePHP Queue Plugin
A robust queue engine for CakePHP 4 that runs each job in its own isolated process, eliminating the most common failure modes of long-lived single-process workers.
Why SpawnQueue?
| Problem | Solution |
|---|---|
| One bad job crashes the whole worker | Each job is a separate process — failure is contained |
| Deploy requires manual worker restart | Graceful shutdown: coordinator drains current jobs, then exits cleanly |
| Long-running jobs lock up other work | Multiple queues with independent concurrency |
| Worker running stale code after deploy | Short-lived child processes always load the latest code |
| No control over retry timing | Exponential backoff + configurable max attempts per queue |
Requirements
- PHP 8.1+
- CakePHP 4.5+
- MySQL 8.0+ or MariaDB 10.6+ (for
SELECT … FOR UPDATE SKIP LOCKED) Older versions fall back automatically — see Claim Strategy - Linux recommended for production (graceful shutdown via POSIX signals)
Installation
Via Composer
Load the plugin in src/Application.php:
Local / in-monorepo development
Add the namespace to your app's composer.json autoload:
Run the migration
SpawnQueue auto-detects whether dereuromark/cakephp-queue is already installed:
- Table exists → adds only the 4 missing columns (
queue,max_attempts,pid,failed_at) - Fresh install → creates the full
queued_jobstable from scratch
Configuration
Override defaults in config/app_local.php or any file loaded in your bootstrap:
Creating Handlers
Implement JobHandlerInterface for new-style handlers:
Dependency note: Handlers are instantiated with
new ClassName(). UseLocatorAwareTrait,ConnectionManager, or other CakePHP service locators for dependencies — constructor injection is not supported in this version.
Exception / return reference
| Thrown / returned | Behaviour |
|---|---|
RetryableJobException($msg) |
Re-queues with automatic exponential backoff |
RetryableJobException($msg, retryAfterSeconds: 300) |
Re-queues with explicit delay |
NonRetryableJobException($msg) |
Marks as failed immediately, no retry |
Any other \Throwable |
Treated as retryable (safe default) |
JobResult::success() |
Marks as done |
JobResult::retry($error) |
Same as RetryableJobException |
JobResult::fail($error) |
Same as NonRetryableJobException |
Legacy dereuromark/cakephp-queue Tasks
Existing tasks that extend Queue\Queue\Task work without any modification.
SpawnQueue wraps them automatically via LegacyTaskAdapter:
Enqueuing Jobs
Running the Coordinator
Run one coordinator per queue when you want separate OS processes, independent restart control, or stronger isolation between high-traffic queues:
For smaller deployments, queue:work-all starts one long-running process that
manages every configured queue:
queue:work-all reads queue names from Configure::read('SpawnQueue.queues').
Both config shapes are supported:
If no queues are configured, queue:work-all falls back to default.
Internally it still creates one QueueCoordinator per queue, each with its own
worker pool and timeout settings, but all coordinators share a single parent
process and one combined TUI dashboard.
Use queue:work-all when operational simplicity matters more than per-queue
process isolation. Use separate queue:work <queue> processes when one queue
has heavy traffic, long-running jobs, or different restart/deploy needs.
Commands Reference
| Command | Description |
|---|---|
queue:work <queue> |
Start coordinator (--max-workers=N, --timeout=N, --show=lines\|tui) |
queue:work-all |
Start one SuperCoordinator for all configured queues (--show=lines\|tui) |
queue:run-job --job-id=N |
Run one job (internal — called by coordinator) |
queue:stats [--queue=name] |
Job counts by queue and status |
queue:requeue-stuck |
Recover jobs stuck in processing (--queue, --timeout) |
queue:retry-failed |
Re-queue failed/dead jobs (--queue, --status, --limit) |
queue:cleanup |
Delete old terminal jobs (--days=30, --status) |
Terminal Output Modes
Controlled by SpawnQueue.show_type config or the --show CLI option:
| Mode | Output |
|---|---|
lines (default) |
Scrolling log lines only — safe for log files and Supervisor |
tui |
Live htop-like dashboard only — useful for interactive monitoring |
Note: In
tuimode the log lines from child processes are suppressed. The dashboard refreshes in-place — do not redirect stdout to a file in this mode.
Job States
Production Setup
Supervisor (recommended)
Single process for all queues:
Separate process per queue:
systemd
Single process for all queues:
Separate process per queue:
Deploy without downtime
Architecture
Claim Strategy
SpawnQueue tries SELECT … FOR UPDATE SKIP LOCKED first.
On older databases (MySQL < 8.0, MariaDB < 10.6) it falls back to a conditional
UPDATE — safe but may cause minor contention on very busy queues.
Migrating from dereuromark/cakephp-queue
- Install SpawnQueue and run the migration (adds columns, keeps all existing jobs)
- Keep dereuromark installed — your app still uses it to write jobs
- Stop the old
bin/cake queue:workerprocesses - Start SpawnQueue coordinators
- Gradually migrate task classes to implement
JobHandlerInterface - Once all tasks are migrated, remove the dereuromark dependency
SpawnQueue picks up both old-style (no queue column) and new-style jobs.
Old jobs are routed to the default coordinator.
Backoff Schedule
| Attempt | Delay before next try |
|---|---|
| 1 | 10 seconds |
| 2 | 30 seconds |
| 3 | 2 minutes |
| 4 | 10 minutes |
| 5+ | 30 minutes |
Override for a specific failure: throw new RetryableJobException($msg, retryAfterSeconds: 3600);
License
MIT