Background tasks

The code that fetches new runs from Strava to add them in the Runnerly database can poll Strava regularly, like every hour. The monthly report can also be called once per month to generate a report and send it to the user by email. Both features are part of the Flask application and use the SQLAlchemy models to do their work.

But unlike user requests, they are background tasks, and they need to run on their own outside the HTTP request/response cycle.

If not using simple cron jobs, a popular way to run repetitive background tasks in Python web apps is to use Celery (http://docs.celeryproject.org), a distributed task queue that can execute some work in a standalone process.

To do this, an intermediate called a message broker ...

Get Python Microservices Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.