flask-djcelery
An example project for configuring Djcelery with Flask application and dynamically adding tasks
- REST API
- Django admin
Quick Setup
Django Admin
- Clone this repository.
- Create a virtualenv and install the requirements.
- Create database using command:
PYTHONPATH=. django-admin.py migrate --settings=celeryconfig
- Start the django server using command:
PYTHONPATH=. django-admin.py runserver --settings=celeryconfig
- Open second terminal window and start local Redis server using command:
./run-redis.sh
. - Start celery worker in another terminal window:
env/bin/celery worker -A app.celery --loglevel=INFO
. - Start celery beat in another terminal window:
PYTHONPATH=. django-admin.py celerybeat --settings=celeryconfig
. - Django Admin can be checked by visiting
http://localhost:8000/
and celery tasks can be added/removed - Flask application can be started as:
python app.py
REST API
- Follow all the above steps
-
GET /interval_schedules/
will list all the schedule intervals -
POST /interval_schedules/
will add a schedule interval- every: 90
- period: seconds
-
GET /periodic_tasks/
will list all the periodic tasks -
POST /periodic_tasks/
will add a new task- name: 'API Task'
- task: 'app.add'
- enabled: True
- args: '[5,5]'
- interval: 1 (would need to be created first using API)
- Similarly
PUT /interval_schedules/1/
will change the interval for tasks on the run- every: 100
- period: seconds