Search code examples
laravelqueuedispatch

Laravel dispatch queue always intermediately run


I am trying to dispatch jobs in Laravel into mysql. If I do

dispatch(new SendBroadcastSMS());

or

SendBroadcastSMS::dispatch()->delay(now()->addMinutes(2));

The job always runs intermediately. In my job, I set to sleep 30 seconds and my current controller/page that calls dispatch also waiting for 30 seconds and echo the job return. Why? It should run in the background via worker right? Or I misunderstand with the laravel queue?

My job is like below:

<?php

namespace App\Jobs;

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

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

    public function __construct()
    {
    }
    public function handle()
    {
        sleep(30);
        echo "test";
//       dd($this->sendSms("6281517777767","test message"));
        //
    }
}

my queue driver is database mysql and I also not receieved any row in job table

QUEUE_DRIVER=database


Solution

  • QUEUE_DRIVER is not the property you should set in your .env file.
    The correct property is QUEUE_CONNECTION.

    QUEUE_CONNECTION=database