Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Tool for generating cron task intervals using a natural syntax
branch: master
Failed to load latest commit information.
lib release 0.4.0
spec added TaskInterval class to output task in cron string
.gitignore added ignore file
CHANGELOG release 0.4.0
LICENSE initial commit
README.rdoc update gem install doc
Rakefile release 0.3.1
TODO added todo ideas
cronos.gemspec release 0.4.0

README.rdoc

Cronos

A Ruby DSL for outputting Cron intervals.

Using a natural syntax to write cron task intervals assists in generating the correct cron interval you are after instead of trying to remember the cron syntax and conventions.

Examples

cron = Cronos::Interval

puts cron.new.hourly
# => '0 * * * *'

puts cron.new.daily
# => '0 0 * * *'

puts cron.new.weekly
# => '0 0 * * 0'

puts cron.new.weekdays.at(12.30)
# => '30 12 * * 1-5'

puts cron.new.weekends.at(12.30)
# => '30 12 * * 0,6'

puts cron.new.at('1.30pm').daily
# => '30 13 * * *'

puts cron.new.every(6).hours.on('15th').of(:january)
# => '0 0,6,12,18 15 1 *' 

puts cron.new.every(20).minutes.on('15th'..'18th').of(:jan, :feb, :mar)
# => '0,20,40 * 15-18 1,2,3 *'

puts cron.new.at(14.45).every(:monday, :tuesday)
# => '45 14 * * 1,2'

You can also output the whole cron task string using the schedule method:

puts Cronos.schedule('some_task').every(:Sunday).at('3am')
# => '0 3 * * 0 some_task'

This does not actually schedule the task in cron. Cronos is merely a DSL to output the cron intervals.

Caveats

Certain combinations produce unintuitive results. They should be obvious but just in case I will list some. Such as

weekly.on_days(:monday, :tuesday)

Will actually run the task twice weekly

TODO: more weird stuff?

Also cron itself allows days of month and days of week to be set. These are independent of each other.

For example:

on_the('15th').of(:jan).on_days(:mon, :tue)

This will be run on the 15th of January AND every Monday and Tuesday of January, so be aware. Though it is a strange combination anyway, the result is the union of both and not the intersection.

Install

sudo gem install cronos

Credits

Adam Meehan (duckpunching.com, adam.meehan@gmail.com)

License

Copyright © 2008 Adam Meehan, released under the MIT license

Something went wrong with that request. Please try again.