Celery process terminated when same callback triggered multiple times

Hi Dash community!

I am trying to run multiple times the same background callback.

Here is the expected behaviour:

  • The callback is triggered every time the user click on a button.
  • The callback takes a few seconds to execute.
  • If the button is clicked again, before the first callback is finished, the callback will be triggered after the first callback has finished.

To do so, I tried to implement a celery queue.
But I am facing an issue because every time I click on the button, it kills the previous processes, as you can see on the screenshot below:

I have tried to add pattern matching callback in order to “change” the callback ID but it didnt work.

Do you have an idea of a workaround? Or maybe there is something wrong I am doing?

Thank you for your time and help.

Arthur

Adding an uuid to the cache_by argument in CeleryManager fixed the issue for me.
This makes sure that a unique cacheKey is created for every request. Background Callback Caching | Dash for Python Documentation | Plotly
However, this effectively disables any caching for the whole CeleryManager instance.

from uuid import uuid4

celery_app = Celery(__name__, broker=os.environ['REDIS_URL'], backend=os.environ['REDIS_URL'])
background_callback_manager = CeleryManager(celery_app, cache_by=[lambda: uuid4()])