<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>duck_punching &#187; gems</title>
	<atom:link href="http://duckpunching.com/topics/gems/feed" rel="self" type="application/rss+xml" />
	<link>http://duckpunching.com</link>
	<description>Ruby, Rails and tech. No ducks were harmed in the making of this blog.</description>
	<lastBuildDate>Thu, 24 Jun 2010 07:12:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Timely assistance with cron intervals using Cronos</title>
		<link>http://duckpunching.com/timely-assistance-with-cron-intervals-using-cronos</link>
		<comments>http://duckpunching.com/timely-assistance-with-cron-intervals-using-cronos#comments</comments>
		<pubDate>Sun, 28 Dec 2008 02:33:09 +0000</pubDate>
		<dc:creator>Adam</dc:creator>
				<category><![CDATA[cronos]]></category>
		<category><![CDATA[gems]]></category>
		<category><![CDATA[cron]]></category>
		<category><![CDATA[dsl]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://duckpunching.com/?p=66</guid>
		<description><![CDATA[For anyone who has used cron before I am sure there have been occasions where you have buggered it up and run the task too few or too many times or at the completely wrong time. I know I have. Its not the cron is terribly hard its just sometimes is not the best mental [...]]]></description>
			<content:encoded><![CDATA[<p>For anyone who has used <a title="Cron" href="http://en.wikipedia.org/wiki/Cron">cron</a> before I am sure there have been occasions where you have buggered it up and run the task too few or too many times or at the completely wrong time. I know I have. Its not the cron is terribly hard its just sometimes is not the best mental map for specifying a repeating interval.</p>
<p>Well as a fun summer project I thought I would create a Ruby DSL for cron to generate the intervals using a more natural syntax to help avoid mistakes. The result is <a title="Cronos" href="http://github.com/adzap/cronos">Cronos</a>. Its influenced by the Active Support time helpers so you can chain together English like commands that you would likely use when describing a repeating interval.</p>
<p>Some examples from the readme:</p>
<pre lang="ruby">
cron = Cronos::Interval
cron.new.hourly.to_s
# => '0 * * * *'
cron.new.daily.to_s
# => '0 0 * * *'
cron.new.weekly.to_s
# => '0 0 * * 0'
cron.new.weekdays.at(12.30).to_s
# => '30 12 * * 1-5'
cron.new.weekends.at(12.30).to_s
# => '30 12 * * 0,6'
cron.new.at('1.30pm').daily.to_s
# => '30 13 * * *'
cron.new.every(6).hours.on('15th').of(:january).to_s
# => '0 0,6,12,18 15 1 *'
cron.new.every(20).minutes.on(15..18).of(:jan, :feb, :mar).to_s
# => '0,20,40 * 15-18 1,2,3 *'
cron.new.at(14.45).on_days(:monday, :tuesday).to_s
# => '45 14 * * 1,2'
</pre>
<p>It would be great to see Cronos integrated it into other cron tools for Ruby as to extend them with DSL to generate just the interval part. The <a title="CronEdit at RubyForge" href="http://cronedit.rubyforge.org/">CronEdit</a> project is one that might find it a useful addition.</p>
<p>Its a first crack and its not magical at all so you can easily jump in and fiddle and perhaps improve it. The code is up on <a title="Cronos as GitHub" href="http://github.com/adzap/cronos">GitHub</a> (where else?!).</p>
<p>UPDATE:<br />
Examples were confusing so clarified the output of each statement irb style.</p>
]]></content:encoded>
			<wfw:commentRss>http://duckpunching.com/timely-assistance-with-cron-intervals-using-cronos/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
