There are multiple download buttons/text there. The way it’s going to work is, when a user clicks on the Download text/option, it’s going to send an Ajax call to the Java RESTful webservice and that thing is going to take time because the stored procedure associated with it could take hours to finish and it could take a while before user gets any response back to the UI.
There’s another table in the backend which start keeping track of the status of the request (like RUNNING, COMPLETE,ERRONEOUS etc) as soon as the call to the main stored procedure is made via an Ajax call.
Since user could send series of requests: By series of requests I mean :
User sends an Ajax request which triggers the backend stored procedure, and this SP is going to take long time.
While the request in Step #1 is still running, user could send another Ajax request ( I don’t know if this is possible or not because I am using Ajax; I might have to use something else to handle (send and receive) asynchronous requests?)
Similarly, if the above two requests are still RUNNING, user could send 3rd request and so on and so forth.
Could anyone please tell me if this is a correct way to handle such requests? I mean, is Ajax should be used in this scenario or something else?
Please let me know if I could elaborate on anything else or if my explanation is unclear. Thanks !
If you do this you’re going to make people think your app has crashed and you run the risk of users hitting the download button multiple times, which sounds like it’ll bring your backend to its knees.
I wouldn’t publicly offer up any endpoints that are going to kick off a backend process that takes hours to complete (bear in mind that you don’t need a browser to send requests to a web service). And are you expecting the user to keep their browsers open until the download is ready? I think I’d bounce tbh.
If I was doing something like this, I’d make a form where users can select whatever they need to download. Have them enter an email address, then mail them a download link when your backend has prepared everything.
Nope. User could go home after they click on download button or they can click on other downloads. Since I would know the status of request, what I could do is, if user try to click on same download button, I could tell them that it’s still RUNNING and not yet COMPLETED. However, they are free to click on other download options. Once everything is finished, I would need to find some way to let the user know like email or something and then have them download the data using a link to the backend path. Does this approach sounds better?
I was wondering is Ajax call going to allow user run multiple download requests? For example, if user decides to click on 3 download options one by one, do you think this would work? Thanks !
Once you start talking about things that take a long time, your AJAX call is out of the question. AJAX requests will time out. You’re going to need a heartbeat call to check if the download is ready or WebSocket connection. The original AJAX call could initiate the request, but if it takes more than a second or 2, you need to use something else to listen for the response.
Yeah, I am worried about the same thing. So if I go ahead with heartbeat call approach, I am still going to stuck with the first request only until it is finished, right? In my scenario, user could initiate another request as well side by side so would this heartbeat approach be still good in this scenario?
When you make the first request to start the process, then your server should respond with a 204 No Content. This says that it was successful but the server has no data to give the client.
From there, you should check another endpoint with a heartbeat to see if it has completed. If it has completed then you download it.
A system I am rewriting does something similar. It was solved by sending the reports to the user’s email because the reports are very time consuming. There is no need for a heartbeat or websocket because the data is handled outside the web client.
So, do I have to program the server to send out this 204 No Content or is it going to happen automatically when an Ajax call is made for the first time (with this first request).
Secondly, when a user decides to hit another download button while the first one is still pending/running, with the approach you have mentioned, it’s not going to block the user, right? By blocking, I mean, user can easily click on other download options and initiate other requests without waiting to have the first one complete, right?
If you go to your Profile Activity page here, you will see a “Download All” button. When you click it and confirm, there is a modal that displays letting you know that the server-side process was initiated.