Running background tasks in a Dash application

Apologies if this is now well known since the release of Dash 2.0.

We have the following setup with our relatively complex, Dash application:

  1. A dockerised backend providing data/authentication to the application
  2. A dockerised frontend, running on gunicorn.

I want to be able to run background tasks where the completion of the task does not impact the users experience.

For example, the user clicks on a button to bookmark something. There will be some visual confirmation for the user and we make an api call to the backend to register that thing has been bookmarked. Both of these processes are conducted within a single callback and so technically, the user has to wait for the completion of both of these things before regaining functionality in the app.

Ideally, we would split this into two separate callbacks where one handles user notification, and the other calls the backend, and the backend call is a background process.

To do this, is it as simple as using dash.long_callback and increasing the gunicorn workers?

I attempted to increase the gunicorn workers in the past but this caused the app to constantly refresh.

This is what our docker file looks like:

FROM python:3.9.7

RUN pip3 install -U pipenv==2021.11.5

COPY ./ /app
WORKDIR /app

RUN pipenv install --system --ignore-pipfile

CMD gunicorn wsgi:application \
            --worker-class=gevent \
            --workers 1 \
            --timeout 90 \
            --log-level=debug \
            --bind 0.0.0.0:80

Let me know if it would be useful to provide any additional information. Thanks in advance!