Hitesh Chauhan
Hitesh Chauhan

Reputation: 1074

How to give priority in laravel jobs?

I am trying to send daily newsletters to my users using laravel Queue jobs. everything is working fine. now the problem is, as I have 50K subscribers so it may take more than one hour to process newsletter jobs. and at the same time, some users registered, but they won't get a confirmation email. they will get the confirmation email only if the newsletter job is completed. how can do solve this problem? I am trying to do this as follows to use onQueue("low").

$job = (new SnippetsnewsletterJob())
   ->onQueue("low");
    dispatch($job);

but the problem not solved!

Upvotes: 0

Views: 1827

Answers (2)

Hitesh Chauhan
Hitesh Chauhan

Reputation: 1074

I find it! if you are trying to run long term task then use runInBackground() in kernel.php file.

$schedule->command('snippets:newsletter')
             ->dailyAt('16:10')->runInBackground();

Upvotes: 0

Collin
Collin

Reputation: 944

You split to jobs across different queues. This way you'll be able to categorize and prioritize them.

Specify wich queue a job belongs to

$this->dispatch((new JobOne())->onQueue('queue1');
$this->dispatch((new JobTwo())->onQueue('queue2');

Now you will be able to spawn multiple queue workers to processs jobs separately:

php artisan queue:work --queue=queue1
php artisan queue:work --queue=queue2

Upvotes: 0

Related Questions