0
votes

I have a class XYJob which was created by artisan command and implements the ShouldQueue class. The QUEUE_DRIVER=redis in the .env file.

The problem is that when i dispatch the job, it runs as a simple php function. The queue listener is not running, but the job runs as a simple function.

It is laravel 5.8 application with predis/predis: ^1.1. I have tried to clear the cache and the config. I have tried to use composer dump-autoload.

namespace Modules\ModuleName\Jobs;

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

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

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        \Log::info('Job is running');
    }
}

Laravel documentation says:

The generated class will implement the ShouldQueue interface, indicating to Laravel that the job should be pushed onto the queue to run asynchronously.

BUT my job is definitely running.

2
Can you share how you are dispatching your job?George Hanson
XYJob::dispatch()->onQueue('custom-queue')Pinter Krisztian

2 Answers

0
votes

Laravel 5.8 application should has QUEUE_CONNECTION in the .env file.

-1
votes

How are you dispatching the job? Have you followed the example on the Laravel doscs site at https://laravel.com/docs/5.8/queues#dispatching-jobs i.e.

\App\Jobs\ProcessPodcast::dispatch($podcast);

or dispatch(new \App\Jobs\ProcessPodcast($podcast);

dispatch(new \App\Jobs\ProcessPodcast($podcast);

If the job is not dispatched in this manner (i.e. you're simply newing up the job class), it will not be pushed to the queue.