benjah
1267
14
Laravel

laravel 5.1 queue job delay doesn't work

Posted 3 years ago by benjah

i trying to set a reminder via laravel 5.1 queue service, the job executes and works fine, the only problem it's that it not delaying the job, i'm not sure if i'm doing it the right way, can someone tell me what am i doing wrong please? my SetReminder job class looks like that

    namespace LM2\Jobs;
   use LM2\Jobs\Job;
   use Illuminate\Queue\SerializesModels;
   use Illuminate\Queue\InteractsWithQueue;
   use Illuminate\Contracts\Bus\SelfHandling;
   use Illuminate\Contracts\Queue\ShouldQueue;
   use LM2\Models\Lead;
   use LM2\Models\User;
   class SetReminder extends Job implements SelfHandling, ShouldQueue
   {
   use InteractsWithQueue, SerializesModels;
   public $user;
   public $lead;
   public function __construct(User $user, Lead $lead)
   {
       $this->user = $user;
       $this->lead = $lead;
   }
   /**
    * Execute the job.
    *
    * @return void
    */
   public function handle()
   {
       $user = new User(['client_id' => 1, 'name'=>'asdasd', 'password' => '123' , 'email' => microtime().'@gmail.com']);
       $user->save();
       }
   }

and the controller function calling that job is:

       public function setReminder($lead_id, Request $request)
   {
       $due_time = $request->input('due_time');
       $message = $request->input('message');
       $user = \Auth::user();
       $lead = Lead::where('_id',$lead_id)->first();
       $lead->reminders = ['message' => $message , 'due_time' => $due_time, 'user_id' => $user->id, 'active' => 1];
       $lead->save();
       $job = (new SetReminder(
               \Auth::user(),
               Lead::find($lead_id)
           ))->delay(10);
       $this->dispatch($job);
       return $lead;
   }

before calling the function i ran php artisan queue:listen at the terminal p.s the new user creating in the handle function it's just for the test.

any answer will help, thanks a lot :)

Please sign in or create an account to participate in this conversation.