Tag archive for: Flask-APScheduler

How to use threading.Condition to wait for several Flask-APScheduler one-off jobs to complete execution in your Python 3 application

Previously, I discussed how to use Flask-APScheduler in your Python 3 Flask application to run multiple tasks in parallel, from a single HTTP request.

When we run jobs as discussed in that post, jobs are ran once by the underlying ApScheduler instance. In addition, our Flask endpoint return the HTTP response back to the HTTP client as soon as the jobs are scheduled.

If we do not want the HTTP client to know the outcome of the jobs within that HTTP call, then we are good. But what if we want to include any errors that the jobs encounter in the same HTTP response?

In such a situation, we will need a mechanism to wait for the one-off jobs to complete execution before returning that response.

Given that in mind, this post shows how we can use threading.Condition to wait for several Flask-APScheduler one-off jobs to complete execution.

How to create an interval task that runs periodically within your Python 3 Flask application with Flask-APScheduler

Previously, I talked about how to use Flask-APScheduler in your Python 3 Flask application to run multiple tasks in parallel, from a single HTTP request.

If you wish to run long running tasks triggered by an HTTP request, then that post will help you do so.

However, what if you want to run jobs periodically without blocking your Flask HTTP server from serving HTTP requests?

In this case, you will want to run an interval task with Flask-APScheduler.

Given that, let’s look at how we can use Flask-APScheduler to create an interval task within your Python 3 Flask application.

How to use Flask-APScheduler in your Python 3 Flask application to run multiple tasks in parallel, from a single HTTP request

When you build an API endpoint that serves HTTP requests to work on long-running tasks, consider using a scheduler. Instead of holding up a HTTP client until a task is completed, you can return an identifier for the client to query the task status later. In the meantime, your HTTP server can offload the task to a scheduler which will complete it and update the status.

When you are building your HTTP server with Python 3 Flask, Flask-APScheduler gives you the facilities to schedule tasks to be executed in the background.

In this post, we look at how we can get Flask-APScheduler to run multiple tasks in parallel, from a single HTTP request.