You can download this code by clicking the button below.
This code is now available for download.
This function creates a Celery task that adds two numbers and logs the result.
Technology Stack : Celery, Python
Code Type : Celery mission
Code Difficulty : Intermediate
def random_celery_function():
import random
from celery import Celery
from celery.utils.log import get_task_logger
app = Celery('tasks', broker='pyamqp://guest@localhost//')
logger = get_task_logger(__name__)
@app.task
def add(x, y):
return x + y
result = add.delay(4, 4)
logger.info(f'The result is {result.get()}')
return result.get()