Nick
Nick

Reputation: 2970

Delete queue job after multiple timeouts in Laravel using Beanstalk

I have a setup where sometimes a job will timeout. The problem is that it keeps hogging the queue and the other jobs won't run.

I want to delete the jobs which timeout 3 times and continue on with the queue. How can I do this? This is specific to laravel 4.2

Upvotes: 1

Views: 926

Answers (1)

Joseph Silber
Joseph Silber

Reputation: 219930

The $job object has an attempts method that tells you how many times it tried to run:

public function fire($job, $data)
{
    // Try to process. If failed:

    if ($job->attempts() >= 3)
    {
        $job->delete();
    }
}

Upvotes: 2

Related Questions