Repository navigation
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #62691
Problem
On Laravel Cloud, foreground scheduled commands always finish with exit code
0, even when the underlying command fails. Because$event->exitCodeis always0:onFailure()andemailOutputOnFailure()callbacks never run.ScheduledTaskFailedis never dispatched byschedule:run.For example:
The root cause is in
CommandBuilder::buildForegroundCommand(). Whenlaravel_cloud()istrue, it wraps the command as:In a shell pipeline, the exit code is the exit status of the last command (
tee), which exits0as long as it can write its output regardless of whethercommandfailed.Solution
Update
CommandBuilder::buildForegroundCommand()forlaravel_cloud()to preserve the scheduled command's exit code using POSIXsh-compatible file descriptor redirection while still piping bothstdoutandstderrthroughtee:shsyntax (compatible withdash,sh,bash, andzsh— noset -o pipefail/bashdependency, which is important because SymfonyProcess::fromShellCommandline()andensureCorrectUser()invokesh -c).stdoutandstderrthroughteeto both$event->output(forsendOutputTo,appendOutputTo,emailOutputOnFailure, etc.) andstdout(whichEvent::execute()forwards to the Laravel Cloud log socket).3>&- 4>&-) inside the command subshell so the command cannot write to or hold them open.user()(sudo -u ... -- sh -c ...) andappendOutputTo()(tee -a).Tests
tests/Console/Scheduling/EventTest.phpcovering built command strings (default,appendOutputTo,user) and actual shell execution preserving non-zero exit codes,stdout/stderr, and file output/appending.tests/Integration/Console/Scheduling/ScheduleRunCommandTest.phpverifyingschedule:runon Laravel Cloud preserves the exit code, triggersonFailure()(and notonSuccess()), dispatchesScheduledTaskFailed, writes the output file, and forwards output to the Laravel Cloud log socket.