Skip to content

How to clean up if a an action fails? #186

Discussion options

You must be logged in to vote

I am actually doing something similar to a clean up and works well.

Just type hint JobDecorator in your asJob() method. Then you can add jobFailed() method to cleanup.

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
}

Replies: 3 comments 3 replies

Comment options

You must be logged in to vote
1 reply
@AlejandroAkbal
Comment options

Comment options

You must be logged in to vote
2 replies
@AlejandroAkbal
Comment options

@AlejandroAkbal
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by AlejandroAkbal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants