Hello everyone!
I use background tasks quite a lot in my Dash Apps and I’ve explored different ways to implement them and monitor their behaviour. During that exploration, I realized that I needed to understand Celery better, so I decided to learn by creating apps that used it in different ways. Here are the results!
In both apps I have included instructions, comments and descriptions to help you if you want to implement something similar for your use case or run the apps in your instance to experiment with them. I have developed and tested them in Dash Enterprise 5 so, if you want to deploy them, you may need to make some modifications in files like project.toml.
Even if you don’t run the apps, the content of the README files and this text will improve a bit your knowledge of Celery tasks in Dash Apps.
Implementing background tasks directly with Celery vs background callbacks
GitHub Repo: GitHub - celia-lm/dash-background-tasks: Sample app with multiple options to run long tasks in the background
This app demoes how to execute background tasks in a Dash App as:
- A scheduled task
- A background callback
- A celery task inside a regular callback
These background tasks generate random data (based in user inputs) that is appended to the existing one in a Redis database and saved there. That data is then retrieved from a regular dash callback to populate a Dash Ag Grid.
Celery monitor app
GitHub Repo: GitHub - celia-lm/dash-celery-monitor: Dash App with a UI to trigger, monitor and cancel Celery tasks
This app allows users to interact with celery tasks (start and cancel them as well as see their progress) inside a Dash App. This app is similar to what flower does, but without running in a different process. Since this monitor is Dash and Python-based, developers have more flexibility to customise the UI.
I hope this is helpful!