Queue Callback execution

Hi everyone,

I have a callback that updates the rows of an ag-grid table.
This callback can be triggered multiple times in a row.

The problem is that when starting the 2nd execution, it stops the run of the 1st execution.

To examplify:

When I open a group in this ag-grid table, it triggers a callback to fetch the data from an API and update the ag-grid table with this new data (I am using my own build of the ag-grid package fyi)

I click successively on the first group and the second group. The first update is interrupted by the start of the second update - as you can see in the logs.

front-end:

callback logs:
image

Is there anyway to queue callback execution?

Thank you,

Arthur

You could try the BlockingCallbackTransform. I believe it does more or less what you want? :slight_smile:

1 Like

Thank you Emil,

So using the BlockingCallbackTransform, it looks like the first callback is not interrupted. However it doesnt send the output of the callback to the dash object. So the table doesnt get updated.

Do you know if there is a way to queue the callback executions? So that the second execution doesnt start before the first one has finished?

thanks

Hey @arthurJacquemart ,

Maybe you could use a background callback and disable all other callbacks until the background callback has finished? Not sure if this makes sense, though. In one case I used a background callback to “block” my app with a full screen spinner.

Hi AIMPED,
Thank you for your answer.
it would indeed solve the issue as the user would not be able to trigger an other callback while the first is still running.

However in term of UX it will not be optimal. The user should be able to open multiple group and just wait for the callbacks to update each of the group.

I am wondering if using a celery job queue would solve the problem. But I cannot find an example of implementation.

Linking a Celery Process | Dash for Python Documentation | Plotly
Celery is a reliable asynchronous task queue/job queue that supports both real-time processing and task scheduling in production systems. This makes Celery well-suited for Dash apps.

You are right, wouldn’t be very nice UX wise.

I never have worked with celery, did you use the forum search?

Google showed this example (one of the first results):

Disclaimer: I did not take a look at the code and checked if this serves your needs :see_no_evil:

1 Like

Celery would be a possible approach to achieve what you want. In fact, I would consider that the more proper option. However, it takes a bit more setup in terms of code as well as infrastructure.

EDIT: Using the blocking callback transform, the output of the first callback should be returned on completion. The second callback (and any others invoked while the first is running) are simply discarded. Is that not what you see? If not, that is a bug.

1 Like

Yes it doesnt send the outputs to the front end.
To be sure of that, I added a simple div to my output list and return it a string that will depend on which group I try to open.
If it was returning the outputs properly, I should see the output of div change twice. However, only the output of the second callback appears.

Writing this I just thought about using long background callback and the blocking callback and send the rows to AG grid using the setprogress function ! I am going to try that

EDIT: unfortunatly blocking callback and long-callback are not compatible, therefore it doesnt work

I manage to get it work by changing how I dealt with the updates on the Agrid side in javascript.

Thank you all for your help, that was super helpful

2 Likes