Laravel 5.7 作业队列未异步运行 [英] Laravel 5.7 jobs queue not running async

查看:45
本文介绍了Laravel 5.7 作业队列未异步运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Laravel 5.7 jobs queue 在我的数据库中进行一些插入/更新,我可能做错了什么,因为当调用该作业时,它似乎阻塞了我的应用程序,因此,不异步运行.我的代码结构如下:

I'm trying to use Laravel 5.7 jobs queue to make some insertions/updates in my database and i problably made something wrong because when the job is called its seems to be blocking my application, therefore, not running asynchronously. My code is in the following structure:

.env

BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120

queue.php

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

'connections' => [

    'sync' => [
        'driver' => 'sync',
    ],

    'database' => [
        'driver' => 'database',
        'table' => 'jobs',
        'queue' => 'default',
        'retry_after' => 90,
    ],

job_caller.php

method_name(){ 
  InsereProspeccao::dispatch($path, $evento, $equipe)->onQueue('jobs');
  retur some_msg_to_user;
}

job_name.php

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

class InsereProspeccao implements ShouldQueue{

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

  private $path = '';
  private $evento = '';
  private $equipe = '';


 public function __construct($path, $evento, $equipe){
     $this->path = $path;
     $this->evento = $evento;
     $this->equipe = $equipe;        
 }

   public function handle(){
      //all program logic
      //access DB for insert/update
   }

}

Obs.:我正在阅读文档,但我找不到问题所在!

Obs.: I'M READING THE DOCUMENTATION, BUT I CANT FIND WHAT'S GOING WRONG !

推荐答案

您使用的是 QUEUE_CONNECTION=sync,它基本上具有同步行为.

You are using QUEUE_CONNECTION=sync which basically has synchronous behavior.

请按以下步骤操作:

  • 运行 php artisan queue:table,它将自动为 jobs 表创建迁移

  • Run php artisan queue:table which will create a migration for jobs table autimatically

运行 php artisan migrate,它将通过运行迁移来创建表

Run php artisan migrate which will create the table by running migration

更改QUEUE_CONNECTION=database,默认情况下会自动使用jobs表来管理队列.

Change QUEUE_CONNECTION=database and as per default, it will automatically take jobs table to manage the queues.

运行php artisan config:clear清除应用配置缓存

那应该很好.查看文档以获得更多帮助.

That should be good to go. Check documentation for more help.

这篇关于Laravel 5.7 作业队列未异步运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆