23 Apr, 2007

Published at 07:52PM

Tagged with site, ruby, rails, and programming

This post has 1 comment

How to automate tasks using Ruby or Rails?

I’ve yet to get the cron job to consistently execute for the flickr and delicious caching. I’ve tried several different things, but nothing seems to work. So I’ve started seeking alternatives. There are three different methods listed, but it’s not obvious to me how they might work. If I were to setup a scheduler, would I then “start” it when Rails initializes in environment.rb? Of all three options, I’m at a loss as to which one I should pursue.

Right now I’m calling refresh_api_cache via a “refresh” link that appears upon login:

1
2
3
4
5
6
7
8
9
10
def refresh_api_cache
  reload_cache(ENV['RAILS_ENV']) and redirect_to :back
end

private

def reload_cache(env)
  command = "ruby #{RAILS_ROOT}/script/custom/api_cache.rb"
  env =~ /development|test/ ? system command : exec command
end

That’s not terribly inconvenient, but it requires two things to happen (tag something in delicious or flickr and then come here and click “refresh”). I want this to be automated. Any tips on scheduling in Ruby/Rails?

Comments

Ilya Grigorik Friday, 27 Apr, 2007 Posted at 06:56PM

Ryan, to answer your question.. If you use BackgrounDRB, it will load your worker when Rails is first initialized. To take it a step further, you can also provide a ‘schedule’, which the worker can follow (ex. refresh cache every x minutes). Take a look at the BackgrounDRB RDoc, there are a lot of interesting features in there which I never discussed in my post.

Do you have something to say about this post?
Retype the image to the right Spam Hint: Are You Human? Textile Formatting Tips

or

Ryan Heath | Site Management A Ruby on Rails production.

This site is a Formed Function. Formed Function LLC | @formedfunction | Get in Touch