- Laravel Version: 5.8.23
- PHP Version: 7.2.16
Steps To Reproduce:
$schedule
->command(Commands\ThrowsExceptionCommand::class)
->cron('* * * * *')
->description('foo')
->emailOutputOnFailure('foo@example.com')
;
$schedule
->command(Commands\DoSomethingCommand::class)
->cron('* * * * *')
->description('bar')
->emailOutputOnFailure('bar@example.com')
;
// This sends an email to foo@example.com with exception.
// This is an correct behavior IMO.
$schedule
->command(Commands\ThrowsExceptionCommand::class)
->cron('* * * * *')
->description('foo')
->emailOutputOnFailure('foo@example.com')
->runInBackground() // <- New Line
;
$schedule
->command(Commands\DoSomethingCommand::class)
->cron('* * * * *')
->description('bar')
->emailOutputOnFailure('bar@example.com')
;
// This works correctly too.
$schedule
->command(Commands\ThrowsExceptionCommand::class)
->cron('* * * * *')
->description('foo')
->emailOutputOnFailure('foo@example.com')
;
$schedule
->command(Commands\DoSomethingCommand::class)
->cron('* * * * *')
->description('bar')
->emailOutputOnFailure('bar@example.com')
->runInBackground() // <- New Line
;
// Not only foo@example.com receives email with exception,
// but also bar@example.com receives email with output of DoSomethingCommand.
$schedule
->call(function () {echo 1;})
->cron('* * * * *')
->description('baz')
->emailOutputOnFailure('baz@example.com')
;
// This ALWAYS sends an email to baz@example.com with empty body.
$schedule
->call(function () {echo 1; throw new \Exception();})
->cron('* * * * *')
->description('baz')
->emailOutputOnFailure('baz@example.com')
;
$schedule
->call(function () {echo 1; throw new \Exception();})
->cron('* * * * *')
->description('baz')
->emailOutputOnFailure('baz@example.com')
->runInBackground()
;
// They work as same as the previous one.
@dinoqqq no sorry, don’t have time atm to deep dive into this.
I see. I think you’re right and might know why this is happening. In the
runCommandInBackground
method the$this->exitCode
isn’t being filled but that’s probably because the command hasn’t finished processing yet. Because the value of theexitCode
property isnull
, it doesn’t equals 0 as expected in theonFailure
method. Maybe there should be anull
check there as well but not sure.@izayoi256 that seems to be the expected behavior? What exactly are you expecting? It’s not very clear from your description.