Hi, I need to run a ruby file when the server starts up and then at 2 second intervals as long as the server is running. What is the preferred way to do this in Rails? Can I put something in the environment.rb or something like that? Currently I made this script a controller with a while true loop that sleeps for 2 seconds before it executes (basically an infinite loop). I run the script by hitting the URL and then I close out my web browser because it never finishes. This is allowing me to test fine but is obviously not a good solution. I am doing all of this on Windows so I can''t use things like BackgroundDB. 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 -~----------~----~----~----~------~----~------~--~---
On Nov 27, 2007 2:19 PM, monarailguy42 <Larry.Erickson-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hi, > I need to run a ruby file when the server starts up and then at 2 > second intervals as long as the server is running. What is the > preferred way to do this in Rails? Can I put something in the > environment.rb or something like that? Currently I made this script a > controller with a while true loop that sleeps for 2 seconds before it > executes (basically an infinite loop). I run the script by hitting > the URL and then I close out my web browser because it never > finishes. This is allowing me to test fine but is obviously not a > good solution. I am doing all of this on Windows so I can''t use > things like BackgroundDB. Thanks.Add a method (that includes your 2 second sleep) to your model, then run it like this: script/runner -e production "Model.method" & -- Greg Donald http://destiney.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 -~----------~----~----~----~------~----~------~--~---
Thanks for the help. Took me a while to get it to work because I forgot to self.methodname since it has to be a class method. Any ideas on how I can get this to start automatically. On Nov 27, 2:27 pm, "Greg Donald" <gdon...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Nov 27, 2007 2:19 PM, monarailguy42 <Larry.Erick...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Hi, > > I need to run a ruby file when the server starts up and then at 2 > > second intervals as long as the server is running. What is the > > preferred way to do this in Rails? Can I put something in the > > environment.rb or something like that? Currently I made this script a > > controller with a while true loop that sleeps for 2 seconds before it > > executes (basically an infinite loop). I run the script by hitting > > the URL and then I close out my web browser because it never > > finishes. This is allowing me to test fine but is obviously not a > > good solution. I am doing all of this on Windows so I can''t use > > things like BackgroundDB. Thanks. > > Add a method (that includes your 2 second sleep) to your model, then > run it like this: > > script/runner -e production "Model.method" & > > -- > Greg Donaldhttp://destiney.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 -~----------~----~----~----~------~----~------~--~---
Can you explain what you''re trying to do in more detail? There may be a better approach. On Nov 27, 2007 2:57 PM, monarailguy42 <Larry.Erickson-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Thanks for the help. Took me a while to get it to work because I > forgot to self.methodname since it has to be a class method. Any > ideas on how I can get this to start automatically. > > On Nov 27, 2:27 pm, "Greg Donald" <gdon...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > On Nov 27, 2007 2:19 PM, monarailguy42 <Larry.Erick...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > > > Hi, > > > I need to run a ruby file when the server starts up and then at 2 > > > second intervals as long as the server is running. What is the > > > preferred way to do this in Rails? Can I put something in the > > > environment.rb or something like that? Currently I made this script a > > > controller with a while true loop that sleeps for 2 seconds before it > > > executes (basically an infinite loop). I run the script by hitting > > > the URL and then I close out my web browser because it never > > > finishes. This is allowing me to test fine but is obviously not a > > > good solution. I am doing all of this on Windows so I can''t use > > > things like BackgroundDB. Thanks. > > > > Add a method (that includes your 2 second sleep) to your model, then > > run it like this: > > > > script/runner -e production "Model.method" & > > > > -- > > Greg Donaldhttp://destiney.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 Nov 27, 2007 2:57 PM, monarailguy42 <Larry.Erickson-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Thanks for the help. Took me a while to get it to work because I > forgot to self.methodname since it has to be a class method. Any > ideas on how I can get this to start automatically.You can make it into a shell script and then put that into a cron job. The shell script will produce a pid you can use to check for to start/stop appropriately: #!/bin/sh script="foo.sh" pidfile="foo.pid" if test -r $pidfile then scriptpid=`cat $pidfile` if `kill -CHLD $scriptpid >/dev/null 2>&1` then exit 0 fi echo "" echo "Stale $pidfile file, erasing..." rm -f $pidfile fi echo "" echo "Couldn''t find script ''$script'' running, running now." echo "" ./$script exit 0 -- Greg Donald http://destiney.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 -~----------~----~----~----~------~----~------~--~---
Part of my application requires communication to a PLC. This PLC has a SOAP web service in which you can access the current points in the PLC. My application needs to poll this SOAP service every couple of seconds and update a database table with the results. Ideally I want this to automatically start when my web server starts up and keep going for the duration that the web server runs. Thanks. On Nov 27, 3:06 pm, "Brian Hogan" <bpho...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Can you explain what you''re trying to do in more detail? There may be a > better approach. > > On Nov 27, 2007 2:57 PM, monarailguy42 <Larry.Erick...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Thanks for the help. Took me a while to get it to work because I > > forgot to self.methodname since it has to be a class method. Any > > ideas on how I can get this to start automatically. > > > On Nov 27, 2:27 pm, "Greg Donald" <gdon...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > On Nov 27, 2007 2:19 PM, monarailguy42 <Larry.Erick...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Hi, > > > > I need to run a ruby file when the server starts up and then at 2 > > > > second intervals as long as the server is running. What is the > > > > preferred way to do this in Rails? Can I put something in the > > > > environment.rb or something like that? Currently I made this script a > > > > controller with a while true loop that sleeps for 2 seconds before it > > > > executes (basically an infinite loop). I run the script by hitting > > > > the URL and then I close out my web browser because it never > > > > finishes. This is allowing me to test fine but is obviously not a > > > > good solution. I am doing all of this on Windows so I can''t use > > > > things like BackgroundDB. Thanks. > > > > Add a method (that includes your 2 second sleep) to your model, then > > > run it like this: > > > > script/runner -e production "Model.method" & > > > > -- > > > Greg Donaldhttp://destiney.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 -~----------~----~----~----~------~----~------~--~---