How to give priority in laravel jobs?

by filiberto , in category: PHP Frameworks , 8 months ago

How to give priority in laravel jobs?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by daisha , 8 months ago

@filiberto 

In Laravel, you can give priority to jobs by setting the public $priority property in your job class. The $priority property should be set to a value between 1 (highest priority) and 10 (lowest priority). By default, jobs have a priority of 5.


Here's an example of how to set the priority of a job:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<?php

namespace AppJobs;

use IlluminateBusQueueable;
use IlluminateContractsQueueShouldQueue;
use IlluminateFoundationBusDispatchable;
use IlluminateQueueInteractsWithQueue;
use IlluminateQueueSerializesModels;

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

    public $priority = 1;

    public function __construct()
    {
        //
    }

    public function handle()
    {
        // Logic for processing job
    }
}


Once you have set the priority of your job, you can dispatch it as usual and Laravel will prioritize the job based on its priority value. Jobs with a higher priority will be processed before jobs with a lower priority.

Related Threads:

How to run queue jobs manually in laravel?
How to run queue jobs manually in laravel?
How to put schedule task jobs in chain in laravel?
How to get specific data from the jobs payload in laravel?
How to give a person a role with buttons in discord.js?
Where to place cron jobs in codeigniter?