# Question on CRON

**URL:** <https://www.ruby-forum.com/t/question-on-cron/180838>\
**Category:** Rails\
**Created:** [December 30, 2009, 4:36am UTC](https://www.ruby-forum.com/t/question-on-cron/180838 "2009-12-30T04:36:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![newb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/2acd7d/32.png) [@newb](https://www.ruby-forum.com/u/newb)\
**Post date:** [December 30, 2009, 4:36am UTC](https://www.ruby-forum.com/t/question-on-cron/180838/1 "2009-12-30T04:36:53Z")

</div>

Dear All,  
i m running cron task in my application using whenever gem.  
the below code runs the rake every month.  
every 1.month, :at =\> ‘11:55pm’ do  
but i want to run this rake on 1st date of every month.  
how can i do it.  
pls guide me on this.

---

<div class="post-metadata">

**Author:** ![newb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/2acd7d/32.png) [@newb](https://www.ruby-forum.com/u/newb)\
**Post date:** [December 30, 2009, 6:55am UTC](https://www.ruby-forum.com/t/question-on-cron/180838/2 "2009-12-30T06:55:12Z")

</div>

Newb N. wrote:

> Dear All,  
> i m running cron task in my application using whenever gem.  
> the below code runs the rake every month.  
> every 1.month, :at =\> ‘11:55pm’ do  
> but i want to run this rake on 1st date of every month.  
> how can i do it.  
> pls guide me on this.

Some one pls help me

---

<div class="post-metadata">

**Author:** ![newb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/2acd7d/32.png) [@newb](https://www.ruby-forum.com/u/newb)\
**Post date:** [December 30, 2009, 8:15am UTC](https://www.ruby-forum.com/t/question-on-cron/180838/3 "2009-12-30T08:15:43Z")

</div>

try : 55 11 01 \* \*

regards

On Wed, Dec 30, 2009 at 12:55 PM, Newb N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> –  
> For more options, visit this group at  
> [http://groups.google.com/group/rubyonrails-talk?hl=en](http://groups.google.com/group/rubyonrails-talk?hl=en).

–  
David A. Prasetya  
Ruby on Rails developer  
@ [http://kiranatama.com](http://kiranatama.com) - a Ruby on Rails outsourcing company

–

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 removed\_email\_address@domain.invalid.  
To unsubscribe from this group, send email to  
removed\_email\_address@domain.invalid.  
For more options, visit this group at  
[http://groups.google.com/group/rubyonrails-talk?hl=en](http://groups.google.com/group/rubyonrails-talk?hl=en).

---

<div class="post-metadata">

**Author:** ![newb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/2acd7d/32.png) [@newb](https://www.ruby-forum.com/u/newb)\
**Post date:** [December 30, 2009, 10:36am UTC](https://www.ruby-forum.com/t/question-on-cron/180838/4 "2009-12-30T10:36:11Z")

</div>

On Dec 30, 2009, at 2:12 AM, David A. wrote:

> try : 55 11 01 \* \*

55 23 1 \* \* …  
so you get 5 min. before midnight (not 5 min. before noon)

> > but i want to run this rake on 1st date of every month.  
> > how can i do it.  
> > pls guide me on this.
> 
> ## Some one pls help me
> 
> –  
> David A. Prasetya  
> Ruby on Rails developer  
> @ [http://kiranatama.com](http://kiranatama.com) - a Ruby on Rails outsourcing company

But to get the help that you seem to be asking for, you’ll have to  
give a bit more information.

Ah! I overlooked the ‘whenever’ gem. Since I found that I have that  
gem installed (although I can’t recall when or why), the docs are  
really sparse and the code doesn’t seem to know how to cope with a  
time or frequency option that will do what you want. In particular,  
lib/outputs/cron.rb says that the :at option can’t be used in this case:

every :month do  
command “something”  
end

gives:

@monthly something

but trying to get what you want with:  
every :month, :at =\> ‘11:55pm’ do  
command “something”  
end

or even:  
every :month do  
command “something”, :at =\> ‘11:55pm’  
end

appears to just give (from line 41):  
ArgumentError: comparison of Time with 0 failed  
although I would have expected (from line 42):  
You cannot specify an ‘:at’ when using the shortcuts for times.

I can get this error if I try something like:  
every :month, :at =\> 1 do  
command “something”  
end  
or even:  
every :month do  
command “something”, :at =\> 1  
end

There seems to be a bug in lib/outputs/cron.rb:41 where @at \> 0  
appears. The @at might be a 0, but is more likely a Time returned  
from Chronic.parse on line 11.

Now, the particulars of using:  
every :month do … end  
to get a crontab line with:  
@monthly …  
might not be exactly what you want since (at least on Mac OS X) the  
man page says:  
string meaning

* * *

@monthly Run once a month, “0 0 1 \* \*”.

Of course, that doesn’t really get you much closer to forcing: “55 23  
1 \* \* …”

I think that you might have to change the behavior in lib/outputs/  
cron.rb to shift from the "@monthly " to the "0 0 1 \* \* " syntax when  
given :at, but also probably adjust the way that the job is created  
and stuffed into the @jobs hash.

In the course of thinking about where and how to make the change which  
would permit one of the nice syntaxes above, I realized that you could  
say:  
every 1.month, :at =\> Time.parse(‘01 23:55’) do  
command ‘something’  
end  
since the parse\_time function only looks at the #min, #hour, and #day  
methods of the given Time:  
55 23 1 \* \* something

It’s a feature of Time.parse to fill-in with parts of the current date/  
time when bits are missing:  
Time.parse(‘01 23:55’)  
=\> Tue Dec 01 23:55:00 -0500 2009

-Rob

Rob B.

[http://agileconsultingllc.com](http://agileconsultingllc.com)  
removed\_email\_address@domain.invalid

> **[Launch Scout Custom Software Development & Software Consulting](https://launchscout.com/)**
>
> We solve digital problems through custom software development and design for the web—apps, mobile, desktop and devices.

removed\_email\_address@domain.invalid

–

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 removed\_email\_address@domain.invalid.  
To unsubscribe from this group, send email to  
removed\_email\_address@domain.invalid.  
For more options, visit this group at  
[http://groups.google.com/group/rubyonrails-talk?hl=en](http://groups.google.com/group/rubyonrails-talk?hl=en).
