Hello, I''d appreciate a hint on how to implement periodic actions in a rails app. I imagine using cron for invoking a ruby script to achieve this. I''m wondering where that script should go and how it should be invoked in cron. I want to use methods from my models to generate simple reports and send them using ActionMailer. maybe some sample of this sort of thing? (a real newbie here ;-) ) -- agnessa _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Hi, I have various scripts that I run from outside rails. Mine all live in the db directory, because they''re all various import type scripts. Start your scripts with the following: #!/usr/bin/env ruby #RAILS_ENV = ''development'' require File.dirname(__FILE__) + ''/../config/environment'' (adjust as necessary) and you can access all your models etc, exactly as if you were running within rails. Cheers, Colin On 31/08/05, Agnieszka Figiel <agnieszka.figiel-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hello, > > I''d appreciate a hint on how to implement periodic actions in a rails app. > I imagine using cron for invoking a ruby script to achieve this. I''m > wondering where that script should go and how it should be invoked in cron. > I want to use methods from my models to generate simple reports and send > them using ActionMailer. maybe some sample of this sort of thing? > > (a real newbie here ;-) ) > > -- > agnessa > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >
http://api.rubyonrails.com/classes/ActionView/Helpers/ JavaScriptHelper.html#M000396 periodically_call_remote(options = {}) Periodically calls the specified url (options[:url]) every options [:frequency] seconds (default is 10). Usually used to update a specified div (options[:update]) with the results of the remote call. The options for specifying the target with :url and defining callbacks is the same as link_to_remote. On Aug 31, 2005, at 11:35 AM, Agnieszka Figiel wrote:> Hello, > > I''d appreciate a hint on how to implement periodic actions in a > rails app. I imagine using cron for invoking a ruby script to > achieve this. I''m wondering where that script should go and how it > should be invoked in cron. I want to use methods from my models to > generate simple reports and send them using ActionMailer. maybe > some sample of this sort of thing? > > (a real newbie here ;-) ) > > -- > agnessa > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Hi Agnieszka, On 31.8.2005, at 18:35, Agnieszka Figiel wrote:> Hello, > > I''d appreciate a hint on how to implement periodic actions in a rails > app. I imagine using cron for invoking a ruby script to achieve this. > I''m wondering where that script should go and how it should be invoked > in cron. I want to use methods from my models to generate simple > reports and send them using ActionMailer. maybe some sample of this > sort of thing?You can use script/runner to invoke your application code from outside the app: (a cron job example from http://wiki.rubyonrails.com/rails/show/HowToRunBackgroundJobsInRails) * * * * * /path/to/app/script/runner -e production "User.clean_up_expired()" Type script/runner --help for usage info. //jarkko> > (a real newbie here ;-) ) > > -- > agnessa > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Jarkko Laine http://jlaine.net http://odesign.fi _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Thanks Colin, it works great! Exactly what I was looking for :-) Adam, thanks for the ajax hint too :-) -- Agnieszka Figiel _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails