1. Learn
  2. /
  3. Courses
  4. /
  5. Deploying AI into Production with FastAPI

Connected

Exercise

Implementing background tasks

Your sentiment analysis API is getting requests to process batch of hundreds of reviews at once. To handle this efficiently without making users wait, you'll implement background task processing so that requests are being processed after sending a response to the client.

Instructions

100 XP
  • Import the background task class from fastapi.
  • Declare the background_tasks parameter to handle the request as a task running in background.
  • Schedule the processing task of analyzing reviews' texts using the process_reviews function.