php - How to get number of queued jobs in IronMQ using Laravel 5.1? -
implementing queues & jobs in laravel 5.1 in project using ironmq, can send jobs ironmq queue see in image bellow :
what want current number of messages in queue (number in red box) in handle function in job, find job code bellow :
class getwords extends job implements selfhandling, shouldqueue{ use interactswithqueue, serializesmodels; /** * create new job instance. */ public function __construct(url $url) { } /** * execute job. */ public function handle() { //getting name of queue dd($this->job->getname()); //return 'words' $currentnumbermsgsinqueue = ?????; //i can't find how //condition if($currentnumbermsgsinqueue == 10){ //do } } }
question : how number of queued jobs (messages) in ironmq queue using laravel ?
after days of searching found answer, there's no method/function
in laravel 5.1 can give number of queued jobs in ironmq.
but against ironmq on-premise api reference give solution, it's rest/http api allow query different requests using javascript set/get want from/to queue (get queue, update queue, list queues ...) , from/to messages in every queue (get message id, messages, clear messages ...).
base url :
https://{host}/{api version}/projects/{project_id}/queues/{queue_name}/messages/webhook?oauth={token}
example, if want number of messages in queue, have get queue info , peek size
result.
get /queues/{queue name}
a practical example :
you can find first base link inside concerned queue in project under webhook url case (see picture bellow) :
js code :
//to queue info have url : /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 :" + 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 } } }
Comments
Post a Comment