Search code examples
phplaravelqueuelaravel-queue

Laravel queue push listener - queue monitoring


I am using the JobProcessing, JobProcessed and JobFailed to populate a queue logs table.

I would like to also listen for an event as jobs are pushed to the queue. Does this exist?

I see from running:

\Redis::lrange('queues:mws', 0, -1)

That a pushedAt parameter exists, but I am unsure how to get this in an event prior to the job actually being processed.

This is fundamentally in order to check that my queues are all:

  • a) actually running (the workers have not stopped).
  • b) the job processing time is not too long.

Solution

  • For anyone wondering, you can get this information when using horizon by listening for the JobPushed event. The payload for this event contains the job ID, name, connetion and queue etc.

    Event::listen(JobPushed::class, function(JobPushed $event){
        \Log::debug('JobPushed Event Fired ', [
            'connection' => $event->connectionName,
            'queue' => $event->queue,
            'payload' => [
                'id' => $event->payload->id(),
                'displayName' => $event->payload->displayName(),
                'commandName' => $event->payload->commandName(),
                'isRetry' => $event->payload->isRetry(),
                'retryOf' => $event->payload->retryOf(),
            ]
        ]);
    });