Laravel 5.5 队列调度不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/48167522/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 17:13:29  来源:igfitidea点击:

Laravel 5.5 Queue Dispatch Not Working

laravelqueuelaravel-5.5dispatch

提问by stoneferry

Maybe I'm not understanding on Laravel queue works, or maybe it itself is not working, my expected behaviour for Laravel Queue/Dispatch is that if a dispatch is initiated from the Controller, the code dispatched to queue should be executed silently and in the background. The end-user browser should not have to wait for the code to execute.

也许我不了解 Laravel 队列的工作原理,或者它本身不起作用,我对 Laravel 队列/调度的预期行为是,如果从控制器启动调度,则调度到队列的代码应该静默执行,并在背景。最终用户浏览器不应等待代码执行。

This is however what happens with my code, the dispatched code to queue leaves the browsers "Spinning..." whilst is executes.

然而,这就是我的代码发生的情况,调度到队列的代码在执行时让浏览器“旋转...”。

Is this expected behavior? The code:

这是预期的行为吗?编码:

    **Controller:**

    public function make_eps_certs($tbl_eps)
    {
        //dd(Carbon::now()->addMinutes(10))
        Log::info('Dispatching maeEPSCert to Queue');
        $var_result=makeEPSCerts::dispatch($tbl_eps)->onQueue('eventadmin')
            ->delay(10);  
return redirect()->back();
}


    **Job:**

    namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;

use App\partSubs;
use Log;

use Image;

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

    /**
     * Create a new job instance.
     *
     * @return void
     */

    protected $passdata;
    public $timeout = 120;

    public function __construct($passdata)
    {
        Log::info('Constructing makeEPSCert');
        $this->passdata = $passdata;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {

    try
        {
        Log::info('Beginning makeEPSCert');
        $tbl_eps=$this->passdata;
    .....

回答by Insax

Change your LOG_DRIVERin your .envto databaseand create the needed migration files with php artisan queue:table, after that do a php artisan migrate.

更改您LOG_DRIVER.envtodatabase并使用 来创建所需的迁移文件php artisan queue:table,然后执行php artisan migrate.

After that you just need to run php artisan queue:work --queue="eventadmin"

之后你只需要运行 php artisan queue:work --queue="eventadmin"

and then you will recognize the expected behavior

然后你会认识到预期的行为

A more detailed documentation can be found here: https://laravel.com/docs/5.5/queues

更详细的文档可以在这里找到:https: //laravel.com/docs/5.5/queues