Question 32
Suppose an endpoint in your flask application triggers a celery task, which generates a CSV file named “data.csv” and saves it in the static folder of a flask application. The file generator takes anywhere between 20 and 40 seconds to generate and save the CSV file.
The below fetch call is used to get the file generated by the above explained celery task.
fetch("/static/data.csv").then(response => response.blob()).then(data => { // does something with the response data})Which of the following is the most efficient way to make the above fetch call so that it doesn’t fail and return the desired response?
Use short polling to check the state of the celery task after every 5 seconds, and make the fetch call, when the task succeeds.
Use javascript function “setTimeout” to make the fetch after 41 seconds, which makes sure that the file is generated and saved to the desired location.