Hi there, do you agree that for having scheduled tasks in Rails, the leanest solution is the following? - Create a controller with an action for each task - Implement the logic of the task as controller code - Set up a cron job at the OS level that uses wget to invoke the URL of this controller/action at the appropriate time intervals Advantages: 1) full access to all your Rails objects just as in a normal controller 2) you can develop and test just as you do normal actions 3) you can also invoke your tasks adhoc from a simple web page 4) You don''t consume any more memory by firing up additional ruby/rails processes My additional question is: How would the cron job entry have to look like in order to let cron "log in" (as admin for example) before calling the action (for obvious security reasons)? This is what I have until now: 20 * * * * /usr/bin/wget --quiet -O - ''http://www.mydomain.com/my_controller/my_action'' Thank you for opinion and/or hints! Tom -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Jeffrey L. Taylor
2010-Jun-03 23:04 UTC
Re: Scheduled tasks in Rails: Cron + wget = Best solution?
Quoting Tom Ha <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>: [snip]> My additional question is: How would the cron job entry have to look > like in order to let cron "log in" (as admin for example) before calling > the action (for obvious security reasons)? This is what I have until > now:One solution is to use HTTP Basic Authentication and curl (wget may be able to do this, I just know abt curl). Also, check for local_request? in the controller (i.e., request is coming from the same computer). HTH, Jeffrey -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Greg Donald
2010-Jun-04 00:48 UTC
Re: Scheduled tasks in Rails: Cron + wget = Best solution?
On Thu, Jun 3, 2010 at 5:12 PM, Tom Ha <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> 20 * * * * /usr/bin/wget --quiet -O - > ''http://www.mydomain.com/my_controller/my_action''Use script/runner. -- Greg Donald destiney.com | gregdonald.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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Tilde Equals
2010-Jun-04 01:25 UTC
Re: Scheduled tasks in Rails: Cron + wget = Best solution?
Tom, I think every scheduled task I''ve seen has called methods on models, not controller actions. Here are some ways I''ve seen it done: 1) Sometimes, for cron jobs run in production, folks will do a "{#RAILS_ROOT}/script/runner -e production ''Model.method'' >> /dev/null 2>&1" 2) There''s repeated_job by ddollar: http://github.com/ddollar/repeated_job. It uses delayed_job, which is pretty sweet. 3) Adam Wiggins wrote a recent blog post about the shortcomings of cron: http://adam.heroku.com/past/2010/4/13/rethinking_cron/. He suggests a combination of rufus-scheduler and Minion+RabbitMQ. Good luck. Tilde Equals On Jun 3, 3:12 pm, Tom Ha <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hi there, > > do you agree that for having scheduled tasks in Rails, the leanest > solution is the following? > > - Create a controller with an action for each task > - Implement the logic of the task as controller code > - Set up a cron job at the OS level that uses wget to invoke the URL of > this controller/action at the appropriate time intervals > > Advantages: > 1) full access to all your Rails objects just as in a normal controller > 2) you can develop and test just as you do normal actions > 3) you can also invoke your tasks adhoc from a simple web page > 4) You don''t consume any more memory by firing up additional ruby/rails > processes > > My additional question is: How would the cron job entry have to look > like in order to let cron "log in" (as admin for example) before calling > the action (for obvious security reasons)? This is what I have until > now: > > 20 * * * * /usr/bin/wget --quiet -O - > ''http://www.mydomain.com/my_controller/my_action'' > > Thank you for opinion and/or hints! > Tom > -- > Posted viahttp://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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Ugis Ozols
2010-Jun-04 05:29 UTC
Re: Scheduled tasks in Rails: Cron + wget = Best solution?
I''m using http://github.com/jmettraux/rufus-scheduler to schedule mail sending. I''ve added scheduling code in config/initializers dir and it''s working quite well. On Jun 4, 1:12 am, Tom Ha <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hi there, > > do you agree that for having scheduled tasks in Rails, the leanest > solution is the following? > > - Create a controller with an action for each task > - Implement the logic of the task as controller code > - Set up a cron job at the OS level that uses wget to invoke the URL of > this controller/action at the appropriate time intervals > > Advantages: > 1) full access to all your Rails objects just as in a normal controller > 2) you can develop and test just as you do normal actions > 3) you can also invoke your tasks adhoc from a simple web page > 4) You don''t consume any more memory by firing up additional ruby/rails > processes > > My additional question is: How would the cron job entry have to look > like in order to let cron "log in" (as admin for example) before calling > the action (for obvious security reasons)? This is what I have until > now: > > 20 * * * * /usr/bin/wget --quiet -O - > ''http://www.mydomain.com/my_controller/my_action'' > > Thank you for opinion and/or hints! > Tom > -- > Posted viahttp://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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hi Tom, I am using BackgrounDRb and it does almost all of requirements you''ve mentioned. Check : http://backgroundrb.rubyforge.org/ Hope this helps! Mutesa -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Mutesa wrote:> Hi Tom, > > I am using BackgrounDRb and it does almost all of requirements you''ve > mentioned. > Check : http://backgroundrb.rubyforge.org/ > > Hope this helps! > > MutesaWheneverize gem -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thanks for all your suggestions! (I like rufus-scheduler pretty much -> small memory foot print...) -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.