【laravel】 Laravel延迟队列

定义延迟队列的两种方式

一 、任务分发的时候指定

\App\Jobs\Jober::dispatch()->delay(20);

二、定义Jober时构造方法中指定

<?php
namespace App\Jobs;
---------------------------------------------------
class Timer implements ShouldQueue
{
   -----------------------------------------------
    public function __construct()
    {
        $this->delay(20);
    }
    /**
     * Execute the job.
     * @return void
     */
    public function handle()
    {
       ---------------------------------------------------
    }
}

三、通过 delay 属性指定

<?php
namespace App\Jobs;
---------------------------------------------------
class Timer implements ShouldQueue
{
     public $delay = 30;
   -----------------------------------------------
    public function __construct()
    {
    }
    /**
     * Execute the job.
     * @return void
     */
    public function handle()
    {
       ---------------------------------------------------
    }
}

猜你喜欢

转载自blog.51cto.com/suiwnet/2428598