Asynchronous Laravel Jobs

不打扰是莪最后的温柔 提交于 2019-12-12 04:45:51

问题


I want to run asynchronous Laravel jobs and work forever. As far as I understand, I need to setup Jobs and push them into separate queues.

I have set .env - QUEUE_DRIVER=database and run php artisan queue:table and php artisan migrate accordingly.

and I have run php artisan make:job MyJob

(at this point queues table is empty though, but I don't know if I did something wrong)

The point I mainly got confused is how is it going to start all the jobs and run them forever, or run the job initially?

As far as I understand, to trigger the job I need to call:

MyFirstJob::dispatch();

but where do I need to call it to work all the time and forever?


回答1:


you need to put all jobs

$schedule->job(new Job1)->everyMinute(); 
$schedule->job(new Job2)->everyMinute(); 
$schedule->job(new Job3)->everyMinute(); 

under schedule() function in kernel.php and than scheduler will handle all the jobs.




回答2:


You can get better idea from this link

https://spiderwebsolutions.com.au/laravel-5-1-and-job-queues-tutorial/



来源:https://stackoverflow.com/questions/47007337/asynchronous-laravel-jobs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!