首页 文章

Laravel调度程序运行队列

提问于
浏览
0

你好,我有一个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
        }

    }
}

为了向队列发送新作业,我正在使用调度方法:

$ this-> dispatch(new ProcessNotifications(['data1','data2','data3'],'slack'));我在作业表中都有ddbb,然后params就可以了

我按运行时间表设置我的crontab:运行每5分钟,启动ok,但是在方法调度上,当调用方法句柄时,params丢失,我在函数调度程序中有这个:protected function schedule(Schedule $ schedule) ){

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

}

然后,这一点上的参数丢失,如果我在控制台php工匠队列工作中运行,我有:

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

在我的ddbb我有所有参数,但我不知道如何恢复或如果这是调用队列的好方法?

1 回答

  • 0

    好吧,我发现,函数句柄下的参数不需要参数,这是队列自动序列化/反序列化

相关问题