- Make sure you have docker installed on your computer
- Pull the repository
- Run
docker-compose up
from project directory - If all goes well, running
docker ps
should show all 3 containers up and running. - In your browser access
http://127.0.0.1:5000/
, if you seeThis is hello world
, then you're all set.
- api/ -- contains flask and celery app code.
- app.py -- flask and celery app setup.
- tasks.py -- simple celery tasks to demontrate some mathematical operations such as addition and subtraction.
- batch_tasks.py -- advance celery tasks that demonstrates batch calculation tasks.
- views.py -- contains flask routes that can be accessed via the api.
- celeryconfig.py -- self explanatory.
- calculator.py -- calculator class with some basic operations to be used by batch celery tasks.
HTTP Methods | URL | Args | Celery Refs | |
---|---|---|---|---|
1 | GET | / | Check app status | |
2 | POST | /basic-task | x:int, y:int | Signature |
3 | POST | /callback-task | x:int, y:int, z:int | Callback |
4 | POST | /chain-task | a:int, x:int, y:int, z:int | Chain |
5 | POST | /simple-chord-task | range:int | Chord |
6 | POST | /chord-task | range:int | Chord |
7 | POST | /batch-start | A route that performs a calculator operation in batches |
- Use postman to test the API endpoints which will trigger the celery tasks.
- Following screenshot shows an example postman session,
Experimenting with a new celery task can be done in 3 steps.
@celery.task()
def new_celery_task(a, b):
return a + b
@app.post('/new-task')
def new_route():
x = 1
y = 2
result = new_celery_task.s(x, y).apply_async()
return str(result.get())
- Restart all three docker containers to make sure the new tasks and routes are registered.
- Call the new route using postman.
- Add an example of redis caching
- Add an example of passing arguments that are not generic python data types
- Add examples of other primitives (group, start, map, etc..)
- Add unit and integration tests