Last active
April 25, 2018 07:09
-
-
Save chanux/6776404 to your computer and use it in GitHub Desktop.
The absolute minimal celerybeat setup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Following is the absolute minimal celerybeat setup. I will use redis as the broker. | |
Install and run redis | |
on Ubuntu | |
sudo apt-get install redis-server | |
on CentOS | |
sudo yum install redis | |
Install celery and redis-py (preferably in a virtual environment) | |
pip install celery redis | |
[Note: I tried this on 3.0.23 (Chiastic Slide). You can check version with celery --version] | |
Have the tasks.py and celeryconfig.py files in a directory and run | |
celery worker -B --loglevel=info | |
Since I print the values in the tasks, you should see 30 (14+16) every 30 seconds and 60 (3*20) every minute. | |
If something is wrong, try running with --loglevel=debug and see whether there's something helpful. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from celery.schedules import crontab | |
from datetime import timedelta | |
BROKER_URL = 'redis://localhost:6379/0' | |
CELERY_RESULT_BACKEND = 'redis://localhost:6379/0' | |
CELERY_IMPORTS = ('tasks',) | |
CELERYBEAT_SCHEDULE = { | |
'every-30-secs': { | |
'task': 'tasks.add', | |
'schedule': timedelta(seconds=30), | |
'args': (14, 16), | |
}, | |
'every-minute': { | |
'task': 'tasks.mul', | |
'schedule': crontab(minute='*/1'), | |
'args': (3, 20), | |
}, | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from celery import Celery | |
celery = Celery('tasks', | |
backend='redis://localhost:6379/0', | |
broker='redis://localhost:6379/0') | |
@celery.task | |
def add(x, y): | |
print x + y | |
return x + y | |
@celery.task | |
def mul(x, y): | |
print x * y | |
return x * y |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment