Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

349
Visualizações
Laravel queue randomly not dispatching

I'm trying to dispatch jobs from a controller, but sometimes the queue works, and sometimes it will execute the code immediately. On the other hand, dispatching from a command works fine, so I wonder what the difference could be.

Things that I have tried:

  • I tried database and Redis connections and got the problem for both connections
  • Without running queue listen/work, the job will randomly execute, so listen/work cannot be the problem
  • Checked webserver/PHP log for errors, no result
  • Something goes wrong before the static dispatch function. When I put a die in the static dispatch function, it will sometimes kill the app, and sometimes it will still run decode in the handle immediately....

vendor/laravel/framework/src/Illuminate/Foundation/Bus/Dispatchable.php

public static function dispatch()
{
    die('xxx');
    
    return new PendingDispatch(new static(...func_get_args()));
}

I'm trying to find what happened before the dispatch function, but I cannot find any function that executes before the static handle function. I have the feeling that something is crashing in PHP and alternatively execute the job immediately, but I cannot find where that happens in the core.

Controller

class CreateTestJob
{
    public function __invoke(Request $request)
    {
        TestJob::dispatch(rand(0, 999999));
    }
}

Job

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

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

    public function handle()
    {
        sleep(30);

        echo 'done';
    }
}

I also tried to create a syntax error in de handle function of the TestJob so that I can see the stack trace, but it shows "1 unknown frame". I wonder what that is

Stacktrace

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

  1. you can check fail_jobs table if there is any error while running your job.

  2. The job will be immediately executed only when you use synchronous driver or synchronous dispatch(for use in local development).

    <?php Somejob::dispatchSync();

  3. Jobs on Redis and database connection will be executed only when you run queue worker.

    php artisan queue:work

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda