# Questions rufus scheduler

**URL:** <https://www.ruby-forum.com/t/questions-rufus-scheduler/186184>\
**Category:** Rails\
**Created:** [April 1, 2010, 7:32pm UTC](https://www.ruby-forum.com/t/questions-rufus-scheduler/186184 "2010-04-01T19:32:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![andersonleite](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/45deac/32.png) [@andersonleite](https://www.ruby-forum.com/u/andersonleite)\
**Post date:** [April 1, 2010, 7:32pm UTC](https://www.ruby-forum.com/t/questions-rufus-scheduler/186184/1 "2010-04-01T19:32:25Z")

</div>

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  
?

---

<div class="post-metadata">

**Author:** ![andersonleite](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/45deac/32.png) [@andersonleite](https://www.ruby-forum.com/u/andersonleite)\
**Post date:** [April 1, 2010, 10:47pm UTC](https://www.ruby-forum.com/t/questions-rufus-scheduler/186184/2 "2010-04-01T22:47:10Z")

</div>

Hm…seems like a better aproach…  
How about this schedule to run every day…is it correct? Looks like  
strange for me have to define the “:first\_at” param…

---

<div class="post-metadata">

**Author:** ![andersonleite](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/45deac/32.png) [@andersonleite](https://www.ruby-forum.com/u/andersonleite)\
**Post date:** [April 1, 2010, 9:52pm UTC](https://www.ruby-forum.com/t/questions-rufus-scheduler/186184/3 "2010-04-01T21:52:48Z")

</div>

Anderson L. 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
