The problem
I’m dispatching a job to execute an action that needs a resource ready to be correctly executed, so if it fails it needs to be retried after some time. But what really happens is that if it fails, it’s not executed ever again. I’m using Supervisor to manage the queue and the database driver and I have changed nothing in my default queue.php config file.
Using Laravel 5.8.
What I’ve tried
I’ve already tried to manually set the number of tries inside the job class like
public $tries = 5;
and also the same thing with retry delay with
public $retryAfter = 60;
My code
I’m implementing this job based on the default job template made with make:job, and my constructor and handle methods look like this:
public function __construct($event, $data) { $this->event = $event; $this->data = $data; } public function handle() { Log::info('Job started | ' . $this->event . ' | Attempt: ' . $this->attempts()); // Executes some logic and throws an Exception if it fails Log::info('Job succeeded | ' . $this->event); }
Finally it doesn’t reach “job succeeded” log and doesn’t log any other attempt other than 1.
Is there some concept I’m missing or is this code wrong somehow?
Advertisement
Answer
That was a very stupid problem actually. But if anyone is as dumb as me ever, I’ll let the solution here.
In my queue.php default driver was set as sync which causes the program to just run the job handle method but it does not queue it, ’cause as I’ve said I didn’t change anything. So I just set it as database and it was fixed.