I''m caching API data from flickr and delicious on my site. I''m using a ruby script that goes out and collects the data, and marshal''s it. For whatever reason, the cron job will not execute, so as a temporary alternative, I''ve placed a "refresh" link that will update the cached files. However, I cannot get this to execute on Dreamhost (works fine on my windows machine). Here''s what I''m trying: 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" case env when /development|test/ system command when /production/ exec command end end If I change the production to be "system command" it won''t crash, but it also won''t do anything. Just refreshes the page. I''ve also tried directly running the script from it''s location: "exec ~/site.com/site/script/custom/api_cache.rb" It seems as though "exec" is crashing, and I''m not sure what to put in that situation. Any tips on how to execute shell commands from Rails??? Thanks! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
try result = `ruby ~/site.com/site/script/custom/api_cache.rb` -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
You could move your script into lib and put its logic into a class with a class method... then you can just call it from your rails code: MyScriptClass.my_script. Then, when you figure out your cron problem (see link [1] provided by Dr. Nic in a response to another post), you can still call this, or you could make a rake task to call it. b [1] http://kb.mediatemple.net/article.php?id=251 rph wrote:> I''m caching API data from flickr and delicious on my site. I''m using a > ruby script that goes out and collects the data, and marshal''s it. For > whatever reason, the cron job will not execute, so as a temporary > alternative, I''ve placed a "refresh" link that will update the cached > files. However, I cannot get this to execute on Dreamhost (works fine on > my windows machine). Here''s what I''m trying: > > 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" > case env > when /development|test/ > system command > when /production/ > exec command > end > end > > If I change the production to be "system command" it won''t crash, but it > also won''t do anything. Just refreshes the page. I''ve also tried > directly running the script from it''s location: > > "exec ~/site.com/site/script/custom/api_cache.rb" > > It seems as though "exec" is crashing, and I''m not sure what to put in > that situation. Any tips on how to execute shell commands from Rails??? > Thanks! >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---