How can I give feedback on the state of a long running method?

I have a method that runs for up to 4 minutes. The method is called by editors and creates a whole lot of content. How can I give the user feeback about the state of the job by showing how many items still have to be created (Progressbar with "Creating items: 150 of 500"). My guess is it can be done with ajax-responses. Do I need to increase the timeout-limit from nginx or will that be invalidated by regular ajax-responses? looks like it does something like that. Does anyone have experience with such a task?

An alternative is to use or such to do the task and inform the user via email once it is done. Ideas?

1 Like

How about sending the info over a websocket?
ie, socket.emit('progress', {'total': 500, 'current': 150})

I've done stuff before with progress that uses an iframe that calls a long request which sterams status items (html or json, I can't remember) which then get read by js and into a progress bar.
However these days I'd be included not to go down that route.
I'd be included to use (or similar like c.taskqueue which is nicer because it can work without any other service like zeo), divide the job up into small batches and then have some js which polls plone about how many of the batches have completed. This scales well and will resume if anything falls over.

This ^^^

Use collective.taskqueue to not block the request. Then create a task for every item or blocks of items (solves problems like conflicts because of long running tasks as well). Use collective taskqueues introspection feature to get the length of the queue. Write an ajax-view and some js to visualize the queue length.

1 Like