Search code examples
laravelqueuejobs

Property precedence of Laravel's queued jobs


I am having a hard time figuring out what is the precedence of properties in laravel's jobs. Currently, I have a job class and tries and timeout property described as shown below:

class ProcessSmsJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    public $tries = 3;
    public $timeout = 300;
    public function __construct()
    {
     //
    }
    public function handle()
    {
     //
    }
}

Say, in server, the queue worker has different properties, for eg. tries = 1 and timeout = 700. What I wanted to know was, if I push this code to a server, will the properties (tries, timeout) defined in server's queue worker take precedence over the currently defined property, or will the server run the queue based on this job's property for this job?

Also, an unrelated question, if a job has tries = 3 and the job was successfully executed on the 2nd attempt, the record is not stored in the failed_jobs table right? So is there a way to determine how many attempts the job took to complete execution?


Solution

  • The documentation states:

    One approach to specifying the maximum number of times a job may be attempted is via the --tries switch on the Artisan command line. This will apply to all jobs processed by the worker unless the job being processed specifies a more specific number of times it may be attempted

    The $tries inside the job class takes precedence.

    Same for the timeout. But make sure your $timeout is never larger than the retry_after setting in your queue.php config file.

    Regarding your second question: Laravel itself is keeping track of the number of times it tries a job. So maybe there is a property on the job itself. Check it. Else, you could try to implement a counter yourself.