简体   繁体   中英

Laravel scheduler run queue

Hello i have a laravel queue for save operations to do later

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')); I have all in ddbb in the job table , then params are ok

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) {

    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 :

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 ?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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