I’ve currently created a custom rake file that does the following:
1.) Checks an External Feed for “NEW” Items
2.) For each new item in the feed array,it updates my Database with a new record
3.) I’ve currently got it on a WHILE loop. The while loop has an (@loopcheck) instance variable that is set to true initially, and if any exception is raised. Resets it to false (so the loop ends).
Here’s an example:
While(@loopcheck) do
begin
....(code here)...
rescue
Exception => e
@loopcheck = false
end
sleep(120)
End
Is this bad coding? Is there a better way to do this? Ideally, I just want to run a background task to simply check for a new feed every 2-3 mins. I looked into Starling/Workling, but that seemed a bit like overkill, and I wasn’t sure about running script/runner via CRON, since it reloads the entire rails environment each time. BackgroundRB a bit overkill too? No?
Just wanted to get some ideas.
Combine cron with the sleep. It will ensure that things don’t completely break down if you hit an exception. Loading “complete rails environment” is not all that bad: 3-6 secs worst case. so run your sleep loop 5 times. and cron the rake task to run every 12 minutes. Makes sense?