0
0
Flaskframework~30 mins

Celery integration overview in Flask - Mini Project: Build & Apply

Choose your learning style9 modes available
Celery Integration Overview with Flask
📖 Scenario: You are building a simple Flask web application that needs to perform background tasks without making users wait. To do this, you will integrate Celery, a tool that helps run tasks in the background.
🎯 Goal: Build a Flask app with Celery integration that can send a background task to add two numbers and return the result asynchronously.
📋 What You'll Learn
Create a Flask app instance
Set up Celery with Flask configuration
Define a simple Celery task to add two numbers
Trigger the Celery task from Flask
💡 Why This Matters
🌍 Real World
Background tasks like sending emails, processing images, or running long calculations without blocking the web server.
💼 Career
Understanding Celery integration is important for backend developers working with Flask to build scalable and responsive web applications.
Progress0 / 4 steps
1
Create Flask app instance
Create a Flask app instance called app using Flask(__name__).
Flask
Need a hint?

Use Flask(__name__) to create the app instance.

2
Configure Celery with Flask settings
Create a Celery instance called celery and configure it with the Flask app's broker URL app.config['CELERY_BROKER_URL'] = 'redis://localhost:6379/0'.
Flask
Need a hint?

Set app.config['CELERY_BROKER_URL'] before creating the Celery instance.

3
Define a Celery task to add two numbers
Define a Celery task called add using the @celery.task decorator that takes two arguments x and y and returns their sum.
Flask
Need a hint?

Use @celery.task to decorate the function add.

4
Trigger the Celery task from Flask route
Create a Flask route /add that calls the Celery task add.delay(4, 6) and returns the task id as a string.
Flask
Need a hint?

Use @app.route('/add') to create the route and call add.delay(4, 6) inside the function.