python - how to get the queue in which a task was run - celery -
i'm new using celery , have question. have simple task:
@app.task(name='test_install_queue') def test_install_queue(): return subprocess.call("exit 0",shell=true) and calling task later in test case like
result = tasks.test_default_queue.apply_async(queue="install") the task run in queue install (because seeing in celery log, , completes fine. know programmatically way of finding in queue task test_install_queue run, object stored in result.
thank you!
edit:
i've changed tasks like:
@app.task(name='test_install_queue',bind=true) def test_install_queue(self): return self.request.__dict__ and i'm using result of apply_async follows:
result = tasks.test_install_queue.apply_async(queue="install") assert "install" in result.get()["hostname"] and workaround worker (hostname) has same name queue initialized in worker.
you can try following approach:
delivery_info = app.current_task.request.delivery_info # default celery uses same name queues , exchanges original_queue = delivery_info['exchange'] queue in app.amqp.queues.itervalues(): if queue.exchange.name == delivery_info['exchange'] , queue.routing_key == delivery_info['routing_key']: original_queue = queue.name break that approach built on assumption use default celery settings , exchanges direct. if need more universal solution fanout , topic exchanges have check routing keys of every declared queue in app.amqp.queues.
Comments
Post a Comment