Laravel queue, redirect after dispatch

1.3k views Asked by At

I have job class in my package. Function is simple but time consuming. I'd like send it to run in background.

php artisan queue:work

works.

<?php
namespace Mypackage\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Support\Facades\Storage;

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

    public $count;
    public $competition;

    public function __construct($count, $competition)
    {
      $this->count = $count;
      $this->competition = $competition;
    }

    public function handle()
    {
//code body
    }
}

and in controller

dispatch((new StartLottery($count, $id))->onQueue('high'));

My default connection for queue is database.

My goal is run this job immediately in background and unlock browser to do another instructions like redirect.

Unfortunately next things are doing after finish job. Finally user wait long time on response from server after his request.

Thanks in advance for any hints how can I move this job to background.

environment:

  • Laravel 5.4
  • php 5.6
  • debian 8
0

There are 0 answers