Skip to content

Commit

Permalink
pass status code to schedule finish
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell authored and driesvints committed Apr 24, 2020
1 parent a4574ea commit b815dc6
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/Illuminate/Console/Scheduling/CommandBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 &'
);
}
Expand Down
14 changes: 14 additions & 0 deletions src/Illuminate/Console/Scheduling/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Console/Scheduling/ScheduleFinishCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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'));
}
}
2 changes: 1 addition & 1 deletion tests/Console/Scheduling/EventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit b815dc6

Please sign in to comment.