-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
[11.x] delegate ProcessDriver@defer()
to ProcessDriver@run()
method
#52807
Conversation
This isn't totally the same. The |
I am on mobile right now, so it is hard to link to source, but on I tried without the |
Link to symfony's docs: https://symfony.com/doc/current/components/process.html#running-processes-asynchronously |
It is actually not in background, but asynchronously, that might be why it kills the child process as soon as the calling process dies. On the issue's code this was working as expected. Although the artisan calling code waits for the child's to end. But the main issue is that passing the command as an array it quotes everything, I even tested passing the I didn't test calling the command as a string, maybe it could work. But unfortunately I am out-of-office right now. |
One more thing, even if I the On Linux, at least, it might be needed to pair it with a command like |
The current code works exactly how I expect it to on my machine. 😅 What OS are you on? |
Anyway, with this PR's code, the deferred closure gets executed after the calling artisan command ends, as I thought it was the expected behavior. I couldn't find in the docs (neither in Laravel's nor in Symfony's) a way to pass additional shell instructions like |
Linux (openSUSE Leap 15.6) |
Did you check the logs output? On the CLI no errors are shown |
laravel-2024-09-16_12.02.49.mp4Just got back at my office, recorded a screencast showing the behavior |
Will go ahead and merge this - though it will keep the FPM worker around while the deferred stuff executes which wasn't totally my intention. |
@taylorotwell I saw this on the codebase, but the framework/src/Illuminate/Console/Scheduling/Event.php Lines 290 to 295 in 79fbf4a
Maybe we can change the I guess it is better to truly send the deferred commands to the background, so it doesn't keep an FPM worker busy. |
Closes #52790
Current implementation of
ProcessDriver::defer()
includes output redirection and background on the command array:framework/src/Illuminate/Concurrency/ProcessDriver.php
Lines 60 to 76 in 05d9204
This ends building up this command line:
As the third-part is quoted, when building the command, Artisan ends up looking for a command called literally
invoke-serialized-closure 2>&1 &
, including the2>&1 &
as the command name, which it fails to find.This PR
Delegates the
ProcessDriver@defer()
to use theProcessDriver@run()
methodSame approach is used by the
ForkDriver
:framework/src/Illuminate/Concurrency/ForkDriver.php
Lines 25 to 28 in 05d9204
I chose this approach as, from the method's docblock description, and from previous implementation (the
&
at the end), the deferred tasks should be run in the background and thus the implementation would be almost the same as theProcessDriver::run()
method (minus the output processing).No tests were added, as this is not dependent on user's parameters, and I have no idea how to write a test to prevent it from happening in the future.