framework: Strange behavior of emailOutputOnFailure() and runInBackground()

  • 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.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 15 (10 by maintainers)

Commits related to this issue

Most upvoted comments

@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 the exitCode property is null, it doesn’t equals 0 as expected in the onFailure method. Maybe there should be a null 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.