How to clean up if a an action fails? #186
-
I've recreated the steps defined here: But the |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
Do you have a reproduction repository? |
Beta Was this translation helpful? Give feedback.
-
You're pointing to the Laravel documentation of a job which differs from an Action being run as a Job. An Action as defined by this package is not a Job as defined by Laravel. Please see https://laravelactions.com/2.x/how-does-it-work.html#decorating-your-actions. The failed hook is not currently supported. Please see |
Beta Was this translation helpful? Give feedback.
-
I am actually doing something similar to a clean up and works well. Just type hint public function handle(Team $team, bool $fullReport = false): void
{
// Prepare report and send it to all $team->users.
}
public function asJob(JobDecorator $job, Team $team)
{
if ($team->someCondition) {
$job->fail('Some condition failed this job');
return;
}
$this->handle($team, true);
}
public function jobFailed(Throwable $e): void
{
// Cleanup
} |
Beta Was this translation helpful? Give feedback.
I am actually doing something similar to a clean up and works well.
Just type hint
JobDecorator
in yourasJob()
method. Then you can addjobFailed()
method to cleanup.