Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

job is not dispatching #29298

Closed
michaelnguyen2021 opened this issue Jul 25, 2019 · 12 comments
Closed

job is not dispatching #29298

michaelnguyen2021 opened this issue Jul 25, 2019 · 12 comments

Comments

@michaelnguyen2021
Copy link

michaelnguyen2021 commented Jul 25, 2019

  • Laravel Version: 5.8.28
  • PHP Version: 7.2
  • Queue Driver: Redis + Laravel Horizon
  • Redis Client: PhpRedis 4.3
  • Redis Server: RedisLabs -> Redis Version Compliance 5.0.4

Description:

Roughly 10,000 jobs are queued and processed per hour. I notice that some jobs are not dispatched. I assume that a lot more jobs are not dispatched but these particular jobs are important so I put logging into them

    // dispatch important job
     ImportantJob::dispatch($task)->onQueue('urgent'); 
<?php

namespace App\Jobs;

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

class ImportantJob implements ShouldQueue
{

    public function handle()
    {
        Log::channel('slack')->alert('Processing Job for Task#' . $this->task->id);
        // do important thing
    }

    /**
     * The job failed to process.
     *
     * @param  Exception  $exception
     * @return void
     */
    public function failed(Exception $exception)
    {
        Log::channel('slack')->alert('Failed to execute Task#' . $this->task->id);
    }

I consistently do not receive some of the jobs and I don't receive any errors reported. So I have to assume that the jobs are not dispatched to Horizon to process.

I don't know if this has to do with Redis 5.0.4 (#29029 ). Out of 10,000 jobs are queued per hours, roughly 100 of important jobs are queued. Roughly 20 of them are not dispatched. That is roughly 20 out of 10,000 jobs I know for sure that do not dispatch. The number of non-dispatched jobs may higher.

Any suggestions?

Steps To Reproduce:

Use Redis Queue with Horizon, create a script that queues roughly 200 jobs per minutes. some of the jobs will not dispatch

@mfn
Copy link
Contributor

mfn commented Jul 25, 2019

Any suggestions?

Use the Job Events https://laravel.com/docs/5.8/queues#job-events to perform a detailed tracking; there two more which are not in the docs and might be useful:

  • ::exceptionOccurred
  • ::failing

@driesvints
Copy link
Member

Closing this issue because it's inactive, already solved, old or not relevant anymore. Feel free to reply if you're still experiencing this issue and we'll re-open this issue.

@zacharias-pavlatos
Copy link

I have the same problem.
Im using database queue .
@michaelnguyen547 did you solved it ?

@fico7489
Copy link

same here

@katjackson
Copy link

I'm having the same issue. I can't tell if the jobs are never dispatched, or if they are dispatched but not picked up.

@zacharias-pavlatos
Copy link

I'm having the same issue. I can't tell if the jobs are never dispatched, or if they are dispatched but not picked up.

Well in my case i have done something wrong with the controllers so my job was never dispatching because i was never calling it . I know its a stupid answer but make sure you are dispatching the job first before you dive deeper .

@cxyguopong
Copy link

I have the same issue

@katjackson
Copy link

In my case, it was an issue with redis memory.

@aidangoodman7
Copy link

I was having a similar issue with inconsistency in dispatching when using the database queue driver. Most jobs were dispatching, but some in particular weren't. Fixed by getting rid of uniqueId() and ShouldBeUnique implementation. I may have been implementing it wrong, but didn't need it anyway.

@ugurarici
Copy link

Today, I had a similar problem on my computer while working on a project.

I found out that the issue was caused by using ShouldBeUnique and a cache problem.

The specific task I was dealing with needed to be unique, following the Illuminate\Contracts\Queue\ShouldBeUnique rules. When I tried to debug by using die() in the task on my development machine, it stopped the process, but the cache related to the task's uniqueness didn't get cleared. This happened because the worker didn't know that the process had finished, as I had forcefully stopped it with die().

In simple terms, the queue handler didn't get the signal that the process had ended, so it didn't clear the necessary cache.

For unique tasks, the application creates a cache key using the formula: 'laravel_unique_job:'.get_class($job).$uniqueId. You can check it here.

To fix the problem, I ran php artisan cache:clear. Instead of using die() or dd() for debugging inside tasks, I now use a simpler approach:

dump($foo);
return;

This change solved my problem.

@NBA707
Copy link

NBA707 commented Feb 8, 2024

I am running into this. A controler has:

Log::info('VendorQuoteImport: Dispatched ' . $cacheKey);
ProecessVendorQuoteProcess::dispatch($cacheKey);

Job has:

public function handle()
    {
        Log::info('Process Vendor Quote Process: ' . $this->cacheKey);
        \Artisan::call("vq:process " . $this->cacheKey);
    }

The log shows the log entry from the controller but not the job itself. I had thought based on searching that the ShouldBeUnique is causing the issue but it is not.

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

Issuing the artisan cache:clear does resolve it but not helpful. I add that as a cron job to execute every hour.

I changed from file cache to redis cache and am testing now, but I really need ::dispatch to work all the time

@tom-it
Copy link

tom-it commented Jul 9, 2024

In my case, it was an issue with redis memory.

please elaborate, I'm facing the same issue, clear cache, optimize, nothing helps, jobs dont get dispatched :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests