Last active
January 23, 2017 06:27
-
-
Save granda/9890890 to your computer and use it in GitHub Desktop.
Create Cronjob for Django Dynamically
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 djcelery.models import PeriodicTask, IntervalSchedule | |
schedule_delta = IntervalSchedule() | |
schedule_delta.every = 30 | |
schedule_delta.period = 'seconds' | |
schedule_delta.save() | |
new_task = PeriodicTask() | |
new_task.name = "30 Second Interval Task" | |
new_task.task = "app_name.tasks.name_of_task" | |
new_task.interval = schedule_delta | |
new_task.save() | |
# ./manage.py celery worker --beat --settings=app.settings.base | |
from celery import task | |
@task | |
def add(first=0, second=1): | |
result = first + second | |
logger.debug('TESTING! {}'.format(result)) | |
return result | |
app.conf.update( | |
CELERY_RESULT_BACKEND='djcelery.backends.database:DatabaseBackend', | |
CELERYBEAT_SCHEDULER='djcelery.schedulers.DatabaseScheduler', | |
BROKER_URL='amqp://guest@127.0.0.1//', | |
CELERY_ACCEPT_CONTENT=['json', 'msgpack', 'yaml'], | |
CELERY_TASK_SERIALIZER='json', | |
CELERY_RESULT_SERIALIZER='json', | |
CELERY_TRACK_STARTED='True', | |
CELERYBEAT_MAX_LOOP_INTERVAL=3, | |
CELERY_TIMEZONE='UTC', | |
) | |
CELERY_TIMEZONE = 'UTC' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment