php - How to create a job for queue:work -


i have job send emails when user registers in application.

sendwelcomeemail.php

<?php  namespace app\jobs;  use app\jobs\job; use app\user; use illuminate\contracts\mail\mailer; use illuminate\contracts\queue\shouldqueue; use illuminate\queue\interactswithqueue; use illuminate\queue\serializesmodels;  class sendwelcomeemail extends job implements shouldqueue {     use interactswithqueue, serializesmodels;      protected $user;     /**      * create new job instance.      *      * @return void      */     public function __construct(user $user)     {         $this->user = $user;     }      /**      * execute job.      *      * @return void      */     public function handle(mailer $mailer)     {         $user = &$this->user;          $message = sprintf('hello %s', $user->name);          $mailer->raw($message, function ($m) use ($user){             $m->from('lucas.nuck@gmail.com', 'lucas lopes');             $m->to($user->email, $user->name);         });     } } 

i create job execute php artisan queue: work command every minute send emails in queue.

easiest way set supervisor.

https://laravel.com/docs/5.4/queues#supervisor-configuration, automatically restart queue:work process if fails.

to solve confusion you:

in app/console/kernel.php file, inside schedule function add command want ran @ specific interval. example : $schedule->command('sendfailedloginsreport')->weekly()->mondays()->at('03:00');

on server, can add cron * * * * * php /path-to-your-project/artisan schedule:run >> /dev/null 2>&1

this cron call laravel command scheduler every minute


Comments

Popular posts from this blog

How to understand 2 main() functions after using uftrace to profile the C++ program? -

c# - Update a combobox from a presenter (MVP) -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -