Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel - Execute queued job automatically [duplicate]

I have jobs to send several emails.

In my controller I call the job:

dispatch(new SendStartPatEmail($data));

And record is saved in table jobs.

But to execute the job I have to run php artisan queued:work manually. How can I do this automatically?

like image 279
user3242861 Avatar asked Jun 21 '18 11:06

user3242861


1 Answers

There are lots of different ways, all depending on the environment that you're using. Laravel tends to recommend using Supervisor to monitor your queue workers and keep them running.

Alternatively, you may wish to have your jobs execute immediately, instead of adding them to a queue. You can do this by setting your queue driver to sync, either in your config:

config/queue.php

'default' => env('QUEUE_DRIVER', 'sync'),

or in your .env file (assuming your config is set up as above)

.env

QUEUE_DRIVER=sync
like image 79
Jonathon Avatar answered Sep 19 '22 13:09

Jonathon