LudoNvl's avatar

Job handle() not called

Hi,

I'm stuck with Queue and jobs issue. I'm working on lumen. I've created jobs and failure migration. I got a Controller and a job. When I call the job in order to dispatch it goes into the constructor well but the handle() method is not called.

$this->dispatch(new FillBrutFec($import));

Then I look into jobs table and the job is insterted.

I put some logs into construct() and handle() :

    protected $import;
    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct(Import $import)
    {
        $this->import = $import;
        Log::debug('construction');
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        Log::debug('handle');
    }

But the handle is not print in logs file.

I've set the QUEUE_DRIVER in .env

QUEUE_DRIVER=database

I don't know what to do..

If you got any ideas, it will be a pleasure to resolve this. Thanks

0 likes
8 replies
bobbybouwmann's avatar

Is your class extending the abstract Job class that should be present in the app/Jobs/ directory?

1 like
LudoNvl's avatar

Yes !

namespace App\Jobs;

use App\Http\Models\Import;
use App\Http\Models\FecBrut;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;

class FillBrutFec extends Job
{

And the Job abstract is like that :

namespace App\Jobs;

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

abstract class Job implements ShouldQueue
{

I've run the queue with php artisan and it runs all the jobs stored in job table but It's not what I want. I would like to run the job directly after dispatch

stefanbauer's avatar

Then you have 2 options:

a) Set your QUEUE_DRIVER to sync to run the jobs sync b) Dispatch it immediately ...->dispatchNow(...)

If you're using a database queue driver, your jobs are throw on a queue. You have to run worker to let them being executed. If you don't like that, do one of the the above things.

4 likes
LudoNvl's avatar

I can't use sync for QUEUE_DRIVERbecause this job can be running more than max_execution_time(120 sec). My job can consums lot of time so it needs to be async. Yes, I'm using database queue driver. But what do you mean by "You have to run worker" ? You mean manually with php artisan queue:work? Otherwise I can try dispatchNow()

stefanbauer's avatar
Level 26

sync and dispatchNow is the same. It will bit dispatched in sync. If you need to run it on queue, your approach is the right one. But you need worker that (yes, queue:work), that run constantly to work on that queue. And as soon as you dispatch a job on the queue, the worker are working that jobs.

LudoNvl's avatar

I see. So I need to run the worker when I use disptach()to run all jobs inside, right ?

stefanbauer's avatar

If you use the ShouldQueue interface and don't use a sync queue driver, yes. You need something, that can handle your jobs async. And that are the workers ;)

LudoNvl's avatar

Ok got it ! Thank you, you enlight my lantern :)

Please or to participate in this conversation.