gpt4 book ai didi

laravel-5.4 - __construct() 方法调用但 handle() 函数未在 laravel 作业中调用

转载 作者:行者123 更新时间:2023-12-02 02:52:37 24 4
gpt4 key购买 nike

我正在尝试使用 dispatch() 方法执行作业

  1. laravel 5.4
  2. redis 服务器
  3. 主管

我已经完成了 queue 配置,例如 'default' => env('QUEUE_DRIVER', 'redis')

  1. 我在我的 app/Services 文件中调用 dispatch() 方法

dispatch(new SavePropertyImages($pid_list));

  1. 以下是我在 app/Jobs 中的作业文件:

    namespace App\Jobs;

    use App\Property;
    use App\Services\CreaBase;
    use Illuminate\Bus\Queueable;
    use Illuminate\Queue\SerializesModels;
    use Illuminate\Queue\InteractsWithQueue;
    use Illuminate\Contracts\Queue\ShouldQueue;
    use Illuminate\Foundation\Bus\Dispatchable;

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

    protected $pid;
    protected $creaBase;
    public $timeout = 300;
    public $tries = 1;
    /**
    * Create a new job instance.
    *
    * @return void
    */
    public function __construct($pid)
    {
    $this->pid = $pid;
    }

    /**
    * Execute the job.
    *
    * @return void
    */
    public function handle()
    {
    $this->creaBase = new CreaBase();
    if (!$this->creaBase->isLogin){
    $this->creaBase->init();
    }
    $this->creaBase->saveAllImages("Property", $this->pid);
    }
    }

当我调用 dispatch(new SavePropertyImages($pid_list)) 方法时,作业的 __construct() 方法调用,但它不调用 handle( ) 函数。

你有什么想法吗?

最佳答案

宾果游戏,我得到了答案

我的 handle() 函数没有调用。因为我设置了一个 supervisor 但没有启动 supervisor 进程,这就是为什么我的 queue:work redis 进程没有启动并且我的工作没有分配给 redis 服务器,我的工作不是执行。

首先,我启动了我的 supervisor 服务,我的 queue 工作正常。

关于laravel-5.4 - __construct() 方法调用但 handle() 函数未在 laravel 作业中调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51381135/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com