GodziLaravel's avatar

Queue job not working on the production server !

Hello ,

In my local sever (Homestead) everything works fine !

But on the prod server when try to run a queue job it's not working at all !

Lets start from the route :

Route::get('test', function () {
    for($currentPage = 1; $currentPage <= 5; $currentPage++){
        $delay = \DB::table('jobs')->count() * 20;
    dispatch(new App\Jobs\ImportCompaniesTeamLeaderJob($currentPage))->delay($delay+1);
    }
});

ImportCompaniesTeamLeaderJob

<?php

namespace App\Jobs;

use App\CustomClass\Teamleader\Sync\CompanySync;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

class ImportCompaniesTeamLeaderJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
    protected $page;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct($page)
    {
        $this->page = $page;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        $company = new CompanySync();
        $company->addOrUpdate(true, $this->page, 20);
    }
}
public function addOrUpdate($manual = false, $pageNumber = 1, $pageSize = 20)
    {

(...)

 foreach ($companiesTeamleader["data"] as $cKey => $cValue) {
            activity()->log("------UPDATE API page($pageNumber, $pageSize)---------->".$cValue["id"]);
			(...)
		}
	}

on Local server (Homestead) I could see the result of activity()->log("------UPDATE API page($pageNumber, $pageSize)---------->".$cValue["id"]);

------UPDATE API page(1, 20)---------->bc74270c-90d5-0184-9f78-6a384259b4a9
------UPDATE API page(1, 20)---------->4ceb7ef2-ea38-0be4-9c78-be6a42361fe5
(..)

On the prod server

In jobs table I see a related row to this queue and after 20 sec (delay) it disappears which is normal and there is nothing in failed_jobs table which means everything is okay ! but nothing within handle is executed !

Any suggestion ?

0 likes
7 replies
tykus's avatar
tykus
Best Answer
Level 104

but nothing within handle is executed

How do you know this?

Also, did you restart the queue worker on production after your code changed (this may be moot depending on your deployment process).

1 like
GodziLaravel's avatar

@tykus In fact That was the problem :

Also, did you restart the queue worker on production after your code changed (this may be moot depending on your deployment process).

Now it works !

GodziLaravel's avatar

I think I found it !

on supervisor I add : database --sleep=3 --queue=default to php artisan queue:work

Then :

sudo supervisorctl reread
sudo supervisorctl update
sudo supervisorctl start laravel-worker:*
tykus's avatar

Ok, but do note that the queue worker would still need restarting after any code changes - the framework is bootstrapped and suspended between handling jobs, it does not bootstrap every time a job is being handled.

1 like
tykus's avatar

No worries, consider marking Best Reply above if I helped.

Please or to participate in this conversation.