Reputation: 9123
I've followed the instruction process to installing and setting up celery, now I'm trying to execute my task. My project tree looks like this:
bin
draft1--
|
-------draft1 ----
|
--------celery.py
--------tasks.py
--------views.py
-------manage.py
-------templates
include
lib
Here's my code:
settings.py
CELERY_BROKER_URL = 'amqp://guest:guest@localhost:5672//'
celery.py
import os
from celery import Celery
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'app.settings')
app = Celery('app')
app.config_from_object('django.conf:settings', namespace='CELERY')
app.autodiscover_tasks()
tasks.py
from celery import shared_task
@shared_task
def print_this():
print('ONE MINUTE')
app.views
print_this.delay()
So my celery function doesn't work, it doesn't execute the print statement. What I want to do is execute the function every minute. Any idea what the problem is?
Upvotes: 6
Views: 19626
Reputation: 7924
I think you need to read more before just starting to experiment. Celery is a distributed task queue, which basically means, it polls a queue to see if there is any task that needs to be run. If there is, it runs the task.
About your setup, you seem to have a task runner, but not the queue that runner requires to poll to check if there is any tasks to be run. The configuration CELERY_BROKER_URL
is about that queue. I suggest you start by reading "Celery's Introduction documents". Especially "What do I need?" part.
NOTE FOR AFTER YOU FIGURE OUT THE QUEUE PART
Also, I am not sure how do you run and serve your django application, but celery requires separate processes. For that part you will need to skim "First Steps with Celery".
Upvotes: 2