RW24
RW24

Reputation: 664

Laravel Jobs and Queues not working as expected

I'm creating an application which generates a video. This is a quite intensive function and takes a few minutes to generate. So I want to create a async process for this. After some research I've read about Jobs and Queues in Laravel.

But now my jobs don't get inserted in the jobs table. I can't find out what I've done wrong.

My function which starts the job:

public function generate() {
    $id = Auth::user()->id;
    GenerateJob::dispatch($id);
}

My Job

<?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;

use Auth;

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

    public function __construct($dossierId)
    {
        $this->dossierId = $dossierId;
    }

    public function handle()
    {
        sleep(5);
    }
}

.ENV QUEUE_DRIVER=database

I did run php artisan clear:config but nothing seems to help.

Nothing I try seems to work. The jobs table remains empty and the job is executed synchronously instead of asynchronously. What am I missing here?

Upvotes: 0

Views: 1502

Answers (1)

RW24
RW24

Reputation: 664

After hours of debugging I finally found a solution to my problem. Adding ->onConnection('database'); to GenerateJob::dispatch($dossier_id); solved it all..

I wish I could say why this was necessary, but I have no clue since I already put that in my .env file. Hope this helps for someone else in this situation. :-)

Upvotes: 0

Related Questions