The task here is a sum of two numbers. To perform this easy task, we have to compose the addTask.py and addTask_main.py script files:
- For addTask.py, start to import the Celery framework as follows:
from celery import Celery
- Then, define the task. In our example, the task is a sum of two numbers:
app = Celery('tasks', broker='amqp://guest@localhost//')
@app.task
def add(x, y):
return x + y
- Now, import the addTask.py file that was defined previously into addtask_main.py:
import addTask
- Then, call addTask.py to execute the sum of two numbers:
if __name__ == '__main__':
result = addTask.add.delay(5,5)