From b815dc6c1b1c595f3241c493255f0fbfd67a6131 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 23 Apr 2020 11:56:23 -0500 Subject: [PATCH] pass status code to schedule finish --- .../Console/Scheduling/CommandBuilder.php | 4 ++-- src/Illuminate/Console/Scheduling/Event.php | 14 ++++++++++++++ .../Console/Scheduling/ScheduleFinishCommand.php | 4 ++-- tests/Console/Scheduling/EventTest.php | 2 +- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/Illuminate/Console/Scheduling/CommandBuilder.php b/src/Illuminate/Console/Scheduling/CommandBuilder.php index 0751d4841b25..bc833bd2710c 100644 --- a/src/Illuminate/Console/Scheduling/CommandBuilder.php +++ b/src/Illuminate/Console/Scheduling/CommandBuilder.php @@ -52,11 +52,11 @@ protected function buildBackgroundCommand(Event $event) $finished = Application::formatCommandString('schedule:finish').' "'.$event->mutexName().'"'; if (windows_os()) { - return 'start /b cmd /c "('.$event->command.' & '.$finished.')'.$redirect.$output.' 2>&1"'; + return 'start /b cmd /c "('.$event->command.' & '.$finished.' "%errorlevel%")'.$redirect.$output.' 2>&1"'; } return $this->ensureCorrectUser($event, - '('.$event->command.$redirect.$output.' 2>&1 ; '.$finished.') > ' + '('.$event->command.$redirect.$output.' 2>&1 ; '.$finished.' "$?") > ' .ProcessUtils::escapeArgument($event->getDefaultOutput()).' 2>&1 &' ); } diff --git a/src/Illuminate/Console/Scheduling/Event.php b/src/Illuminate/Console/Scheduling/Event.php index 00692764bb3b..be8b6065c116 100644 --- a/src/Illuminate/Console/Scheduling/Event.php +++ b/src/Illuminate/Console/Scheduling/Event.php @@ -262,6 +262,20 @@ public function callAfterCallbacks(Container $container) } } + /** + * Call all of the "after" callbacks for the event. + * + * @param \Illuminate\Contracts\Container\Container $container + * @param int $exitCode + * @return void + */ + public function callAfterCallbacksWithExitCode(Container $container, $exitCode) + { + $this->exitCode = (int) $exitCode; + + $this->callAfterCallbacks($container); + } + /** * Build the command string. * diff --git a/src/Illuminate/Console/Scheduling/ScheduleFinishCommand.php b/src/Illuminate/Console/Scheduling/ScheduleFinishCommand.php index c7f4c12b78ac..c19381f08a51 100644 --- a/src/Illuminate/Console/Scheduling/ScheduleFinishCommand.php +++ b/src/Illuminate/Console/Scheduling/ScheduleFinishCommand.php @@ -11,7 +11,7 @@ class ScheduleFinishCommand extends Command * * @var string */ - protected $signature = 'schedule:finish {id}'; + protected $signature = 'schedule:finish {id} {code=0}'; /** * The console command description. @@ -37,6 +37,6 @@ public function handle(Schedule $schedule) { collect($schedule->events())->filter(function ($value) { return $value->mutexName() == $this->argument('id'); - })->each->callAfterCallbacks($this->laravel); + })->each->callAfterCallbacksWithExitCode($this->laravel, $this->argument('code')); } } diff --git a/tests/Console/Scheduling/EventTest.php b/tests/Console/Scheduling/EventTest.php index a579eead2746..d4dfe2312d36 100644 --- a/tests/Console/Scheduling/EventTest.php +++ b/tests/Console/Scheduling/EventTest.php @@ -29,7 +29,7 @@ public function testBuildCommand() $commandSeparator = ($isWindows ? '&' : ';'); $scheduleId = '"framework'.DIRECTORY_SEPARATOR.'schedule-eeb46c93d45e928d62aaf684d727e213b7094822"'; - $this->assertSame("(php -i > {$quote}{$defaultOutput}{$quote} 2>&1 {$commandSeparator} {$quote}".PHP_BINARY."{$quote} artisan schedule:finish {$scheduleId}) > {$quote}{$defaultOutput}{$quote} 2>&1 &", $event->buildCommand()); + $this->assertSame("(php -i > {$quote}{$defaultOutput}{$quote} 2>&1 {$commandSeparator} {$quote}".PHP_BINARY."{$quote} artisan schedule:finish {$scheduleId} \"$?\") > {$quote}{$defaultOutput}{$quote} 2>&1 &", $event->buildCommand()); } public function testBuildCommandSendOutputTo()