问题
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