Here is an overview of my workflow:
- The
PdfFilestable has 3 columns:id,statusandfile. - The form calls a server callable
start_pdf_generation(some_id)and sets theintervalof a timer to 1. - The server function
start_pdf_generationstarts the background taskpdf_generation. - The
pdf_generationbackground task adds a row to thePdfFilestable with theidand thestatus, then it starts collecting info (it can take a minute ot two). While collecting info it updates thestatuson that row. When all the info is ready, it uses it to render the PDF, then stores it to thefilecolumn and sets thestatusto'done'. - While that happens, the
tickevent of the timer keeps calling a server callableget_pdf_generation_status(some_id)and updating aself.status_label.text. - When the status is
'done', theget_pdf_generation_statusreturns the PDF file for download and thetickevent sets theintervalback to 0 to stop the polling.
I use a column for the status instead of the task status, because I was having some problems with checking the task status. I don’t remember the details, perhaps it was too slow? The disadvantage is that, if the status on the table never changes, you don’t know if it’s because the background task crashed or because it is genuinely taking a long time.
These are little implementation details, and you can play around with it. I hope you get the idea. On one end it’s more difficult than it should be. On the other hand you have all the freedom and control over what you can do.