[英]How to get number of queued jobs in IronMQ using Laravel 5.1?
Implementing queues & jobs in Laravel 5.1 in my project using IronMQ , I can now send jobs to the IronMQ queue like you see in image bellow : 使用IronMQ在我的项目中在Laravel 5.1中实现队列和作业,我现在可以将作业发送到IronMQ队列,如下图所示:
What I want now is to get the current number of messages in queue (number in red box) in the handle function in my job, find job code bellow : 我现在想要的是在我的工作中的句柄函数中获取当前队列中的消息数(红色框中的数字),找到下面的作业代码:
class GetWords extends Job implements SelfHandling, ShouldQueue{
use InteractsWithQueue, SerializesModels;
/**
* Create a new job instance.
*/
public function __construct(Url $url)
{
}
/**
* Execute the job.
*/
public function handle()
{
//getting the name of queue
dd($this->job->getName()); //return 'words'
$currentNumberMsgsInQueue = ?????; //i can't find how
//Condition
if($currentNumberMsgsInQueue == 10){
//Do something
}
}
}
Question is : How to get number of queued jobs (messages) in IronMQ queue using Laravel ? 问题是:如何使用Laravel获取IronMQ队列中的排队作业(消息)数量?
After days of searching I found the answer, there's no method/function
in Laravel 5.1 that can give us the number of queued jobs in IronMQ . 经过几天的搜索,我找到了答案, Laravel 5.1中没有
method/function
可以为我们提供IronMQ中排队的作业数量 。
But against IronMQ On-Premise API Reference give us a solution, it's a REST/HTTP API that allow us to query different requests using javascript to set/get all what we want from/to queue (Get Queue, Update Queue, List Queues ...) and from/to messages in every queue (Get Message by Id, Get all Messages, Clear Messages ...). 但是针对IronMQ On-Premise API Reference为我们提供了一个解决方案,它是一个REST / HTTP API ,允许我们使用javascript查询不同的请求来设置/获取我们想要的所有内容/队列(Get Queue,Update Queue,List Queues)。 ..)和从/到每个队列中的消息(按ID获取消息,获取所有消息,清除消息...)。
https://{Host}/{API Version}/projects/{Project_ID}/queues/{Queue_Name}/messages/webhook?oauth={Token}
https:// {Host} / {API Version} / projects / {Project_ID} / queues / {Queue_Name} / messages / webhook?oauth = {Token}
Example, if we want the number of messages in queue, we have just to Get Queue Info and peek the size
from result. 例如,如果我们想要队列中的消息数量,我们只需要获取队列信息并从结果中查看
size
。
GET /queues/{Queue Name}
A Practical Example : 一个实际例子:
You can find your first base link inside the concerned queue in your project under Webhook URL case (see picture bellow) : 您可以在Webhook URL case下的项目中的相关队列中找到您的第一个基本链接(参见下图):
JS code : JS代码:
//To get queue info we have url : GET /queues/{Queue Name}
var url = "https://{Host}/{API Version}/projects/{Project_ID}/queues/{Queue_Name}?oauth={Token}";
//Using ajax $.get
$.get( url ,
function( result ) {
alert( "Queue size is :" + result["queue"]["size"]);
});
Result : 结果:
{
"queue": {
"project_id": 123,
"name": "my_queue",
"size": 0,
"total_messages": 0,
"message_timeout": 60,
"message_expiration": 604800,
"type": "pull/unicast/multicast",
"push": {
"subscribers": [
{
"name": "subscriber_name",
"url": "http://mysterious-brook-1807.herokuapp.com/ironmq_push_1",
"headers": {
"Content-Type": "application/json"
}
}
],
"retries": 3,
"retries_delay": 60,
"error_queue": "error_queue_name",
"rate_limit": 10
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.