Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django Celery Task does not execute with .delay

Tags:

django

celery

I am able to execute my task no problem using

    scrape_adhoc_reporting([store], [types], inventory)

This is a problem though, because this task can easily take an hour. So I try to make the task async. I tried both of following:

    scrape_adhoc_reporting.apply_async(args=[[store], [types], inventory])
    scrape_adhoc_reporting.delay([store], [types], inventory)

Both of these methods did not work. The view just redirects as it should, but the task never gets executed. There are no errors in the error log. Any insight as to what I am doing wrong?

Edit: After looking around a little bit more, I see people talking about registering a task. Is this something I need to do?

like image 836
Jacob Valenta Avatar asked Apr 05 '13 12:04

Jacob Valenta


People also ask

What does delay do in Celery?

For the delayed execution calls, you will see a shared_task instance instead of the result of the executed function. The primary reason for this is to allow the task to be run later, canceled later, or interrupted later. Later is the key phrase because the delayed execution task will now be run by the celery worker.

How do you use Celery beat in Django?

To use the Celery Beat, we need to configure the Redis server in the Django projects settings.py file. As we have installed the Redis server on the local machine, we will point the URL to localhost. The CELERY_TIMEZONE variable must be correctly set to run the tasks at the intended times.


2 Answers

I ran in the same issue and I just solved it. MattH is right: this is due to non-running workers.

I'm using Django (1.5), Celery (3.0+) and Django-Celery on Windows. To get Celery Beat working, I followed this tutorial: http://mrtn.me/blog/2012/07/04/django-on-windows-run-celery-as-a-windows-service/ as on Windows, Beat can only be launched as a service.

However, as you, my tasks were launched but not executed. This came from a bug in the packaged version django-windows-tools (from pip).

I fixed the issue by downloading the latest version of django-windows-tools from GitHub (https://github.com/antoinemartin/django-windows-tools).

like image 124
humble.jok Avatar answered Sep 20 '22 01:09

humble.jok


If you want it to be run remotely, you need a worker process running with that task loaded and a routing system configured to get the task request sent between the caller and the worker.

Have a look at the celery documentation for workers and tasks.

The code that you're running is just executing the task locally.

like image 42
MattH Avatar answered Sep 22 '22 01:09

MattH