-
Notifications
You must be signed in to change notification settings - Fork 21
Add Subprocess Job Execution Support #178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 2.x
Are you sure you want to change the base?
Conversation
c80bb73 to
849f868
Compare
| } | ||
|
|
||
| try { | ||
| $data = json_decode($input, true, 512, JSON_THROW_ON_ERROR); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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), | ||
| ]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indentation.
|
|
||
| $exitCode = proc_close($process); | ||
|
|
||
| if ($exitCode !== 0 && empty($output)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could the output ever be '0'?
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.