lorisleiva / laravel-actions

⚡️ Laravel components that take care of one specific task
https://laravelactions.com
MIT License
2.52k stars 123 forks source link

Handle a job failure #161

Closed robert-abram closed 2 years ago

robert-abram commented 2 years ago

Is it possible to handle failed job in laravel actions like in orginal laravel queue, method failed ?

https://laravel.com/docs/8.x/queues#dealing-with-failed-jobs


    /**
     * Handle a job failure.
     *
     * @param  \Throwable  $exception
     * @return void
     */
    public function failed(Throwable $exception)
    {
        // Send user notification of failure, etc...
    }
travisaustin commented 2 years ago

Within my own projects, I defined a new JobDecorator that I use to do this. In my JobDecorator, it looks for a function called jobFailed() on the Action itself, and calls that function if the job does fail.

I've submitted a PR #166 to add this functionality to Laravel Actions. I hope this helps!

lorisleiva commented 2 years ago

Fixed by #166. Will be part of the next release (very soon, feel free to use dev-main for now 🙂).

alex-osborn commented 2 years ago

Hi. This is a great update - thanks.

I'm running into an error with the current release version (v2.4.0), while running my project which is using PHP 8.0.18. This is a valid version per the package requirements (^8.0).

Cannot unpack array with string keys

Looks like this is the line causing the error:

Lorisleiva\Actions\Decorators\JobDecorator:150

$this->fromActionMethod('jobFailed', [$e, ...$this->parameters], []);

Looks like this pull request introduced a dependency on PHP 8.1, because array unpacking with associative keys was only introduced in that version. https://php.watch/versions/8.1/spread-operator-string-array-keys

Possibly bump the version for the next release or look at tweaking this?

lorisleiva commented 2 years ago

Hi there 👋 Thanks for raising this. I think this is probably more a change in Laravel since I've never seen this parameters array be associative. Would you mind opening another issue for this?