Dear all I created a module in my_rails_project/lib/ssc.rb. I can execute the method in rails console (i.e. SSC::Monitor.method1(a,b)). How can I execute the method regularly? I am using Linux, can I do it using `crontab`? Thank you. module SSC class Monitor def self.method1(a,b) bla bla bla some code will access the model class end def self.method1(a,b) end end end Many thanks Valentino -- 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 -~----------~----~----~----~------~----~------~--~---
Dear all I tried script/runner for this, but every execution need to initialize the rails environment. Any other good idea for it? What is your good/best practice? Many thanks Valentino -- 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 -~----------~----~----~----~------~----~------~--~---
Especially if this method is accessing your models, I don''t see a way around loading your entire rails environment. I think a more common solution would be to create a rake task which you invoke with cron... On Feb 12, 10:53 pm, Valentino Lun <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Dear all > > I tried script/runner for this, but every execution need to initialize > the rails environment. Any other good idea for it? What is your > good/best practice? > > Many thanks > > Valentino > -- > 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-/JYPxA39Uh5TLH3MbocFFw@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 -~----------~----~----~----~------~----~------~--~---
> I think a more common solution would be to create a rake task which > you invoke with cron...Thank for your reply How can I do it with rake task? Can you give me some reference? Thanks again Valentino -- 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 -~----------~----~----~----~------~----~------~--~---
Check out http://railscasts.com/episodes/128-starling-and-workling and http://railscasts.com/episodes/130-monitoring-with-god There are a number of different ways to have a task persist, and run on a regular schedule. I''ve also previously used background-db and cron seems to be a popular option. I tend to go with whatever has the easiest tutorials that i can find! Anyone else feel free to weigh in if you have any more suggestions. -- 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 -~----------~----~----~----~------~----~------~--~---
Hi look this http://www.railsenvy.com/2007/6/11/ruby-on-rails-rake-tutorial -- 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 -~----------~----~----~----~------~----~------~--~---
I use cron to schedule wget: wget http://localhost:3000/cron cron_controller invokes your method -- 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 -~----------~----~----~----~------~----~------~--~---
That''s a great idea, until someone in the outside finds out about that path/resource. You''re opening up too much and scriptkiddies can get happy attempting a DoS. Wondering if you handle that somehow (IP address check or something)? -----Original Message----- From: Mario Gutierrez <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> Reply-to: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Subject: [Rails] Re: Schedule job in rails Date: Fri, 13 Feb 2009 16:55:27 +0100 I use cron to schedule wget: wget http://localhost:3000/cron cron_controller invokes your method --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Harold A. Gimenez wrote:> That''s a great idea, until someone in the outside finds out about that > path/resource. You''re opening up too much and scriptkiddies can get > happy attempting a DoS. Wondering if you handle that somehow (IP address > check or something)?How about using HTTP basic authentication so only authorized clients can access the controller action? Which would be only your rake task. I haven''t thought this through, It''s just the first thing that came to mind. -- 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 -~----------~----~----~----~------~----~------~--~---
If there are no hostile users on the server, in the controller: if local_request? do the action else ignore or log hostile action end HTH, Jeffrey Quoting Harold A. Gimenez <harold.gimenez-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:> That''s a great idea, until someone in the outside finds out about that > path/resource. You''re opening up too much and scriptkiddies can get > happy attempting a DoS. Wondering if you handle that somehow (IP address > check or something)? > > -----Original Message----- > From: Mario Gutierrez <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > Reply-to: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > To: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > Subject: [Rails] Re: Schedule job in rails > Date: Fri, 13 Feb 2009 16:55:27 +0100 > > > I use cron to schedule wget: > > wget http://localhost:3000/cron > > cron_controller invokes your method--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Mario Gutierrez wrote:> I use cron to schedule wget: > > wget http://localhost:3000/cron > > cron_controller invokes your methodThanks, it is a very good idea. How about if my action require 2 parameters? How to do that? Thanks again Valentino -- 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 -~----------~----~----~----~------~----~------~--~---
That can be spoofed Blog: http://random8.zenunit.com/ Learn rails: http://sensei.zenunit.com/ On 14/02/2009, at 4:21 AM, "Jeffrey L. Taylor" <ror-f/t7CGFWhwGcvWdFBKKxig@public.gmane.org> wrote:> > If there are no hostile users on the server, in the controller: > > if local_request? > do the action > else > ignore or log hostile action > end > > > HTH, > Jeffrey > > Quoting Harold A. Gimenez <harold.gimenez-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>: >> That''s a great idea, until someone in the outside finds out about >> that >> path/resource. You''re opening up too much and scriptkiddies can get >> happy attempting a DoS. Wondering if you handle that somehow (IP >> address >> check or something)? >> >> -----Original Message----- >> From: Mario Gutierrez <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> >> Reply-to: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org >> To: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org >> Subject: [Rails] Re: Schedule job in rails >> Date: Fri, 13 Feb 2009 16:55:27 +0100 >> >> >> I use cron to schedule wget: >> >> wget http://localhost:3000/cron >> >> cron_controller invokes your method > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
>> wget http://localhost:3000/cron >> >> cron_controller invokes your method > > Thanks, it is a very good idea. How about if my action require 2 > parameters? How to do that?Let me further elabroate on my question. For example in my Cron Controller def someaction some_method(params[:one],params[:two]) end Is it possible to do this in my crontab as follow? 10 10 * * * wget http://localhost:3000/cron/someaction "para1" "para2" Many thanks Valentino -- 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 -~----------~----~----~----~------~----~------~--~---
On Saturday 14 February 2009 12:52 am, Valentino Lun wrote:> Is it possible to do this in my crontab as follow? > > 10 10 * * * wget http://localhost:3000/cron/someaction "para1" "para2"I''m not sure, but an alternative is to put the wget command in a small shell script (Linux talk, iiuc) or a .bat file (MS talk, iiuc). Then invoke that shell script or .bat file from cron. Randy Kramer -- I didn''t have time to write a short letter, so I created a video instead.--with apologies to Cicero, et.al. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
No quite like that. If you''re sending an HTTP GET request to any URL, you would pass parameters to the URL itself, something like: http://localhost:3000/cron?param1=value1¶m2=value2 etc What looks attractive to me about this approach (of using wget via cron instead of a rake task) is that you are not bringing up an entire rails environment to handle a task. There''s less overhead. Just be sure to lock it down with a combination of things that have been suggested here: IP Address check, local_request?, http basic authentication. There may be more you can do... On Sat, Feb 14, 2009 at 12:52 AM, Valentino Lun < rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > >> wget http://localhost:3000/cron > >> > >> cron_controller invokes your method > > > > Thanks, it is a very good idea. How about if my action require 2 > > parameters? How to do that? > > Let me further elabroate on my question. For example in my Cron > Controller > > def someaction > some_method(params[:one],params[:two]) > end > > Is it possible to do this in my crontab as follow? > > 10 10 * * * wget http://localhost:3000/cron/someaction "para1" "para2" > > Many thanks > > Valentino > -- > 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 -~----------~----~----~----~------~----~------~--~---
Citation needed. Quoting Julian Leviston <julian-AfxEtdRqmE/tt0EhB6fy4g@public.gmane.org>:> > That can be spoofed > > Blog: http://random8.zenunit.com/ > Learn rails: http://sensei.zenunit.com/ > > On 14/02/2009, at 4:21 AM, "Jeffrey L. Taylor" <ror-f/t7CGFWhwGcvWdFBKKxig@public.gmane.org> > wrote: > > > > > If there are no hostile users on the server, in the controller: > > > > if local_request? > > do the action > > else > > ignore or log hostile action > > end--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> def someaction > some_method(params[:one],params[:two]) > end > > Is it possible to do this in my crontab as follow? > > 10 10 * * * wgethttp://localhost:3000/cron/someaction"para1" "para2" >You will need to pass the para1, and para2 to the someaction method so at a minimum you have to change the signature of the someaction method as below: def someaction para1, para2 ... end now within this method you can do anything you want only thing is that this method needs to be public in scope and you need to make sure that it requires no authentication otherwise your wget request will fail. I usually use script/runner in Rails for such needs. wget may or may not work depending on how restful your routes are and controller action is. Bharat --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---