rubyonrailsin

A Ruby and Rails talk

Thursday, April 1, 2010


[Rails] Re: questions rufus scheduler

by rubyonrailsin 0 comments

Tag


Share this post:
Design Float
StumbleUpon
Reddit

Anderson Leite wrote:
> Hello people,
> I am using Rufus scheduler to send emails every day at 4am. To do this I
> am using:
>
> scheduler = Rufus::Scheduler.start_new
> scheduler.every '1d', :first_at => '2010/04/1 04:30' do
> #do something
> end
>
> There is a better way to write this schedule ?
>
>
> By the way, I placed this code at config/environments/production.rb, but
> don't seems to me that is the correct place. Is this the best way to go
> ?

I created a file called config/initializers/task_scheduler.rb which
looks like this:

scheduler = Rufus::Scheduler::PlainScheduler.start_new

scheduler.every "7m" do
sweep_for_reports
#puts "#{Time.now.to_s(:db)} -- Swept for reports."
end

scheduler.cron '22 1 * * *' do
gather_event_data
puts "#{Time.now.to_s(:db)} -- Gathered data."
end

_________
An easier way to write your schedule, probably, is to use cron-style.
4AM every day would be like this (this, mind you, is a matter of
preference!):

scheduler.cron '0 4 * * *' do
send_emails :to => these_guys :about => that
end
--
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@googlegroups.com.
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.

No comments:

Post a Comment

Subscribe feeds via e-mail

Blog Archive