Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5.5 Queue Dispatch Not Working

Maybe I'm not understanding on Laravel queue works, or maybe it itself is not working, my expected behaviour for Laravel Queue/Dispatch is that if a dispatch is initiated from the Controller, the code dispatched to queue should be executed silently and in the background. The end-user browser should not have to wait for the code to execute.

This is however what happens with my code, the dispatched code to queue leaves the browsers "Spinning..." whilst is executes.

Is this expected behavior? The code:

    **Controller:**

    public function make_eps_certs($tbl_eps)
    {
        //dd(Carbon::now()->addMinutes(10))
        Log::info('Dispatching maeEPSCert to Queue');
        $var_result=makeEPSCerts::dispatch($tbl_eps)->onQueue('eventadmin')
            ->delay(10);  
return redirect()->back();
}


    **Job:**

    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 App\partSubs;
use Log;

use Image;

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

    /**
     * Create a new job instance.
     *
     * @return void
     */

    protected $passdata;
    public $timeout = 120;

    public function __construct($passdata)
    {
        Log::info('Constructing makeEPSCert');
        $this->passdata = $passdata;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {

    try
        {
        Log::info('Beginning makeEPSCert');
        $tbl_eps=$this->passdata;
    .....
like image 692
stoneferry Avatar asked Jan 09 '18 11:01

stoneferry


Video Answer


2 Answers

Change your LOG_DRIVERin your .env to database and create the needed migration files with php artisan queue:table, after that do a php artisan migrate.

After that you just need to run php artisan queue:work --queue="eventadmin"

and then you will recognize the expected behavior

A more detailed documentation can be found here: https://laravel.com/docs/5.5/queues

like image 177
Insax Avatar answered Oct 03 '22 16:10

Insax


You can try again in the following way (I assume that you did instructions in Laravel docs but someday it's not working):

Step 1: drop table 'jobs' in your database.

Step 2: run command 'php artisan migrate' in console to create table 'jobs' again.

Step 3: run command 'php artisan queue:work' in console

Step 4: retry your app

Note that in .env file, you set up:

QUEUE_CONNECTION=database

QUEUE_DRIVER=database

P/s: It works for me!

like image 34
kilo636 Avatar answered Oct 03 '22 15:10

kilo636