I have an issue and as of now I have no idea about how to solve it..
Basically I have in my application a function that takes a long time to execute. When the user starts that function a certain commmand is submitted to a queue for asynchronous processing. On the UI side the user is displayed a page saying that the function is being processed and that it may take a long time. Behind that page there is an action checking periodically on the status of the processing. If the processing is done the next page is displayed, otherwise the user stays on the same page.
The user may decide not to wait and just go to a different page. Everything works fine but the problem is that the action checking on the status of the transaction keeps being executed, until the transaction finishes, after that since anyway the user is gone to a different page he won't be forwarded to the next page for that action, and this is fine.
I just want to figure out how I can intercept in the action checking on the status of the processing that the user has left the page and is not waiting for the end of the transaction anymore.
At the moment, I can think of a couple of different strategies to deal with it. There're probably others, which I also would like to hear.
- Option 1: Instead of making the "processing" action check if the user still is viewing the original page, you could have the original page sending temporary requests (every 10 seconds, for example) to the server saying it's still there. If the server doesn't receive this requests in a while, the action knows that the user has left the original page.
- Option 2 (don't really think it's a good idea; it doesn't scale well and doesn't separate concerns well): If the user has a limited number of pages he can go to after starting the process, and this number is small (and not likely to grow), you could make the actions associated with these pages "send a message" to the "processing" action warning that the user has left the original page.
SCJP 1.4, SCWCD 1.4
Of course, I found a very beautiful couch. Definitely. And this tiny ad: