Skip to content

Strange behavior of emailOutputOnFailure() and runInBackground() #28992

@izayoi256

Description

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions