Laravel queue push listener - queue monitoring

[亡魂溺海] 提交于 2021-02-19 04:17:01

问题


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.

回答1:


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(),
        ]
    ]);
});


来源:https://stackoverflow.com/questions/54598551/laravel-queue-push-listener-queue-monitoring

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!