开发者

Fetching Data for Ruby's Rack App in specific time interval

I have a very simple ruby rack app which retrieves information from a webservice and converts it to JSON.

#config.ru

my_result = fetch_information_from_webservice
map '/feed' do
   run Proc.new {|env| [200, headers... , my_result.to_json]}
end

So when starting the server it fetches the information, cache it and display the results withing /feed. What I would like to do is from time to time reload that fetch_information_from_webservice re-assigning my_result a brand new value

So let's say, every 30 min the server will fetch external information again, cache it to the /feed and display it very quicly without bother the user.

Is there any way to do it without having to create an external script and load it 开发者_运维技巧as a cron job (like declaring inside the own configu.ru file?

Thanks in advance


Rufus Scheduler seems to do exactly what I wanted it's very neat and runs smoothly.

one thing I've had to do is run the app through Sinatra instead of pure rack since the raw Rack app wasn't refreshing the results accordingly on the /feed call, but with Sinatra is works pretty well.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜