简体   繁体   English

Laravel Scheduler运行队列

[英]Laravel scheduler run queue

Hello i have a laravel queue for save operations to do later 您好,我有一个laravel队列,以后可以进行保存操作

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 SumoCoders\Teamleader;
use Illuminate\Notifications\Messages\SlackMessage;
use Monolog\Handler\Slack;
use Illuminate\Support\Facades\Mail;

/**
 * Class ProcessNotifications
 *
 * @package App\Jobs
 * Worker for send the notifications slack / mail / teamleader in asincr way
 */

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

    protected  $arrayDataNotification ;
    protected  $typeNotification;
    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct($arrayDataNotification , $typeNotification)
    {
        $this->typeNotification = $typeNotification;
        $this->arrayDataNotification = $arrayDataNotification;
        \Log::debug('createNotif',$arrayDataNotification);
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle($arrayDataNotification , $typeNotification)
    {
        //first get type of notification
        \Log::debug('debug handle ',$this);
        \Log::info('into handle '.$this->typeNotification);

        if($this->typeNotification=='mail'){
        //mail internal

        }

        if ($this->typeNotification=='slack'){
        //notifications slack
        }

        if($this->typeNotification=='teamleader'){
        //teamleader connection
        }

    }
}

For send aa new job to the queue i am using dispatch method : 为了将新工作发送到队列中,我正在使用调度方法:

$this->dispatch(new ProcessNotifications(['data1', 'data2', 'data3'], 'slack')); $ this-> dispatch(new ProcessNotifications(['data1','data2','data3'],'slack')); I have all in ddbb in the job table , then params are ok 我把所有的东西放在工作表的ddbb中,然后参数就可以了

i setted my crontab by run schedule:run each 5 minutes, is launched ok , but on method schedule , when the method handle is called , the params are lost , and i have this in the function scheduler: protected function schedule(Schedule $schedule) { 我通过运行schedule设置了我的crontab:每5分钟运行一次,启动正常,但是在方法schedule上,当调用方法句柄时,参数丢失了,并且我在函数调度程序中有以下内容:protected function schedule(Schedule $ schedule ){

    Log::debug('running scheduler '.date("d-m-Y H:i:s"));
$schedule->job(ProcessNotifications::dispatch());

}

Then , the params in this point is lost, same if i run in console php artisan queue work i have : 然后,在这一点上的参数丢失了,如果我在控制台php artisan队列工作中运行,则具有相同的条件:

Too few arguments to function App\Jobs`\ProcessNotifications::__construct()`

in my ddbb i have all params, but i dont know how recover or if this is the good way to call the queue ? 在我的ddbb中,我具有所有参数,但是我不知道如何恢复,或者这是否是调用队列的好方法?

好的,我发现,函数句柄下的参数不需要参数,这将自动为队列进行序列化/非序列化

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM