queue icon indicating copy to clipboard operation
queue copied to clipboard

Add Subprocess Job Execution Support

Open josbeir opened this issue 1 month ago • 0 comments

This PR adds support for running queue jobs in isolated subprocesses. That allows code changes to take effect immediately without restarting long‑running workers, speeding up iterative development and reducing workflow friction. Subprocess execution also contains job failures to the child process, improving stability of the main worker and making debugging safer and more predictable.

Key Features

Subprocess Execution: New SubprocessProcessor wraps the standard processor to execute jobs in isolated PHP processes via proc_open(), communicating job data and results over stdin using JSON.

CLI Command: SubprocessJobRunnerCommand handles single job execution within the subprocess, accepting job data via STDIN and returning results via STDOUT.

Worker Integration: Added --subprocess flag to WorkerCommand to enable subprocess mode. Also configurable via Queue.subprocess config key.

Configuration

// Enable globally
Configure::write('Queue.subprocess', true);

// Or use CLI flag
bin/cake queue worker --subprocess

Note about logging to stdout

As messaging between worker and sub command is using stdout with json i decided to redirect all other stdout logging to stderr. This seemed like a fine balance as subprocesses would only be used locally. And even if they where to be used in production for any reason (memory, crash resilience?) then a dedicated log engine could be used instead.

josbeir avatar Dec 17 '25 14:12 josbeir