I want to make a rails app that displays accumulated data from activerecord when a user loads the web page. To accumulate the data I want to have a background task that goes out every 5 minutes (roughly) and gets the data and then stores it in activerecord. How can I have rails start this background process when I start the rails app? Thanks, John. -- 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.
You can implement a rake task that builds the data and initiate the task using CRON. However, it really depends on what your idea of accumulated data is to be honest. If a user is hitting your web page you can create an action that instantiates the loading and updates a database. Or, if the data is something that is being accumulated through creations or updates, then you can use callbacks in your model to perform actions. What type of data are you trying to accumulate? Here''s a brief example of something I created to tag when a person hits a view in my app: class ApplicationController < ActionController::Base protected def instantiate_sitestats(page) site_stats = Sitestat.find_by_user_id_and_pages_visited(@current_user.id, page) if site_stats site_stats.update_attributes(:clicks => (site_stats.clicks + 1), :last_time_clicked => Time.now.in_time_zone) else Sitestat.create(:user_id => @current_user.id, :pages_visited => "#{page}", :clicks => 1, :last_time_clicked => Time.now.in_time_zone) end end end .. then in each controller I want to mark this occurence I do: def index instantiate_sitestats("Home Index") if user_signed_in? end This allows me to track any page a user visits, if the user is signed in. You can create your own trackables as well. If you are looking more for notifications, or internals, you might want to look at Rails'' notifications, although some are heavy and intensive loads. Otherwise, cron or model callbacks are your best bet. Hope it helps. -- 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.
use delayed_jobs On Jul 24, 2011, at 18:25 , John Sayeau wrote:> I want to make a rails app that displays accumulated data from > activerecord when a user loads the web page. > > To accumulate the data I want to have a background task that goes out > every 5 minutes (roughly) and gets the data and then stores it in > activerecord. How can I have rails start this background process when I > start the rails app? > > Thanks, > John. > > -- > 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.-- ==============================================================================Tomas Meinlschmidt, MS {MCT, MCP+I, MCSE, AER}, NetApp Filer/NetCache www.meinlschmidt.com www.maxwellrender.cz www.lightgems.cz ============================================================================== -- 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.
Alpha Blue wrote in post #1012740:> You can implement a rake task that builds the data and initiate the task > using CRON. > > "However, it really depends on what your idea of accumulated data is to > be honest. "The data is environmental. I want to be able to take a reading of temperature, humidity and pressure at regular intervals. The interval could be minutes or seconds. I''m not sure it even has to be part of the rails app. It just has to update activerecord. What I was hoping was that there was a way to start this process at the same time as the rails app. I guess I could have a startup script that starts both. -- 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.
Hi John, What I usually do in cases like yours is that I''ll create a runnable script that is run using rails runner (like $ ./script/rails runner -e production ./script/fetch_save_foo.runnable), and then use cron to run that script on some ongoing basis (where I typically have a crontab per project where all cron''d events related to that project are kept). The ability to easily develop/test/run scripts using your existing app''s models/etc via runner (using the same exact calls you would/ could make in console) is one of the nicest built-in features of rails. Jeff On Jul 24, 1:45 pm, John Sayeau <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Alpha Blue wrote in post #1012740: > > > You can implement a rake task that builds the data and initiate the task > > using CRON. > > > "However, it really depends on what your idea of accumulated data is to > > be honest. " > > The data is environmental. I want to be able to take a reading of > temperature, humidity and pressure at regular intervals. The interval > could be minutes or seconds. > > I''m not sure it even has to be part of the rails app. It just has to > update activerecord. What I was hoping was that there was a way to start > this process at the same time as the rails app. I guess I could have a > startup script that starts both. > > -- > 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.
Thanks Jeff. -- 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.