Reputation: 589
I have a little django project that creates a XLSX report using XlsxWriter getting records from a database using the following "pseudo" python code:
global myWorkbook
myWorkbook = Workbook("my_report.xlsx", {'constant_memory':true})
db_conn = databases.getDbConnection()
table1_thread = threading.Thread(target=generate_sheet, args=("table1", db_conn))
table1_thread.start()
table2_thread = threading.Thread(target=generate_sheet, args=("table2", db_conn))
table2_thread.start()
table3_thread = threading.Thread(target=generate_sheet, args=("table3", db_conn))
table3_thread.start()
table4_thread = threading.Thread(target=generate_sheet, args=("table4", db_conn))
table4_thread.start()
#Threads joining here...
db_conn.close()
return myWorkbook
These tables that I'm doing the SELECT's are really huge (about 50 thousand rows) and takes a long time to generate the report (from 2 to 8 minutes).
In my front end I want to use an ajax request to start the report generation and to show a "Download button" when the report is done in ajax success function.
But I'm facing a timeout issue after the click on "Generate Report" button. I searched the Internet and I figure out that I can't change this ajax timeout.
So, I would like to now: What should I do to accomplish this objective? I don't have the possibility to save the reports in the server because they are heavy (about 40~60MB) and it's generated every day.
Upvotes: 0
Views: 628
Reputation: 111
I am not 100% sure if this will help you or not but I was thinking following approach:
In Django: Run a celery task https://docs.celeryproject.org/en/latest/index.html (documentation) https://buildwithdjango.com/blog/post/celery-progress-bars/ (Basic web search) https://blog.miguelgrinberg.com/post/using-celery-with-flask (Flask Implementation)
In Frontend:
Ajax call will invoke Celery task
While the task is running "download in progress or some user friendly text"
after getting task complete response "Download complete"
Upvotes: 1