I want to do something like the following: when a user clicks on a button, I send an ajax request to a server and a server starts doing a background IO operation while the user immediately receives a response says "it's started". That's it for the user.
On the server that background operation is going on. The operation should execute, say, 10 times in 10 minutes. It's something like periodic polling a status of something, say, a database. In the status has changed in less than 10 minutes, the operation should stop immediately, so it can be 1 minute or 3 minutes. Otherwise the operation keeps going. And at most it's 10 times within 10 minutes.
I surely don't want to use any third-party libraries because I know I can do that by the means of pure ruby or Rails. It doesn't matter that it's more difficult.
How can I do that?
I know, I should create a Thread, but how exactly should I do that part "constantly polling a status of something during 10 minutes at most once in a minute, at most 10 times and if the some condition is true then you're done, finish right away."
Note that's a simplified version of what I want but the idea is what I've described.