Conversation
c80bb73 to
849f868
Compare
| } | ||
|
|
||
| try { | ||
| $data = json_decode($input, true, 512, JSON_THROW_ON_ERROR); |
There was a problem hiding this comment.
What's 512? Can we use the union of the flag constants?
| while (!feof(STDIN)) { | ||
| $chunk = fread(STDIN, 8192); | ||
| if ($chunk === false) { | ||
| break; | ||
| } | ||
|
|
||
| $input .= $chunk; | ||
| } |
There was a problem hiding this comment.
Could we read input from $io Using stdin will make this harder to test/mock/change in the future.
|
|
||
| /** | ||
| * Configure logging to use STDERR to prevent job logs from contaminating STDOUT. | ||
| * Reconfigures all CakePHP loggers to write to STDERR with no additional formatting. |
There was a problem hiding this comment.
Why? Won't that break logging outputs to files/syslog log drain services?
| return [ | ||
| 'success' => false, | ||
| 'error' => sprintf('Subprocess output exceeded maximum size of %d bytes', $maxOutputSize), | ||
| ]; |
|
|
||
| $exitCode = proc_close($process); | ||
|
|
||
| if ($exitCode !== 0 && empty($output)) { |
There was a problem hiding this comment.
Could the output ever be '0'?
|
@josbeir you want to continue on this one? :D I just merged 2.x => 2.next and this would be a new feature, so it would be cool to rebase this on 2.next |
i can look into it but its a bit flakey currently because communicating between the process and subprocess goes over stderr/stdio which is hacky and difficult to differentiate between errors/statusses. I think a better communication system should be explored before merging this. |
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
SubprocessProcessorwraps the standard processor to execute jobs in isolated PHP processes viaproc_open(), communicating job data and results over stdin using JSON.CLI Command:
SubprocessJobRunnerCommandhandles single job execution within the subprocess, accepting job data via STDIN and returning results via STDOUT.Worker Integration: Added
--subprocessflag toWorkerCommandto enable subprocess mode. Also configurable viaQueue.subprocessconfig key.Configuration
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.