Laravel队列推送监听器-队列监视 [英] Laravel queue push listener - queue monitoring

查看:66
本文介绍了Laravel队列推送监听器-队列监视的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 JobProcessing JobProcessed JobFailed 填充队列日志表.

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?

我从跑步中看到:

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

存在pushAt参数,但是我不确定在实际处理作业之前如何在事件中获取此参数.

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)实际正在运行(工人尚未停止).
  • b)作业处理时间不太长.

推荐答案

对于任何想知道的人,在使用Horizo​​n时,您都可以通过监听 JobPushed 事件来获取此信息.此事件的有效负载包含作业ID,名称,连接和队列等.

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

这篇关于Laravel队列推送监听器-队列监视的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆