I have two servers: one works with a django application, and the other works both the rabbitmq queue and the celery worker. My .py tasks on the server running the queue / worker contain the task as follows:
@task(queue="reports") def test_task(): time.sleep(120)
My goal is to accomplish this task from a django view. Since the task code is on a different server than the django view, which I would call a task, I am trying to use the following code to send a task from django to a working computer.
send_task("tasks.test_task", task_id=task_id, args=[], kwargs={}, publisher=publisher, queue=queue)
I found this method here , but so far testing has not worked.
I am testing with the -F tail on the celery worker work file on the celery worker server, then navigating to the view URL containing send_task in the browser. I am looking for a task to show how "received" in the tail output, but it is not.
The celery workerโs log level is DEBUG, the log file shows that the task is registered with the appropriate name, and the django settings.py application contains the correct IP address and credentials for the rabbitmq server. When trying different approaches, I sometimes saw an error message in the celery log file when I changed the line passed to send_task to what was an invalid task (i.e. send_task ('asdf')). This caused an UnregisteredError in the log file. However, this only happens occasionally, and so far, while testing various combinations of settings and calls, I have not found a way to reliably replicate behavior.
Also, this is the corresponding settings.py section in the django project (with actual values โโremoved):
CELERY_RESULT_BACKEND = 'amqp' BROKER_HOST = 'the.correct.IP.address' BROKER_USER = 'the_correct_user' BROKER_PASSWORD = 'the_correct_pass' BROKER_VHOST = 'the_correct_vhost' BROKER_PORT = 5672
I googled around and did not find much on send_task. Any ideas on what I can do wrong?