How to do it...

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:

  1. For addTask.py, start to import the Celery framework as follows:
from celery import Celery
  1. 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
  1. Now, import the addTask.py file that was defined previously into addtask_main.py:
import addTask
  1. Then, call addTask.py to execute the sum of two numbers:
if __name__ == '__main__':
result = addTask.add.delay(5,5)

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset