ANN: crone - cron in Erlang (sort of)

Chris Pressey <>
Thu Jul 4 09:19:45 CEST 2002


Hi all.

Realizing I'd soon need something like it, and surprised to not find
anything existing quite like it, I wrote this little application in
Erlang.  crone is a task scheduler, something like cron, but also a bit
different.  As a testament to the ease of programming in Erlang, this
program took only one day to write, once the idea had gelled.

For each task you wish to schedule, crone creates a process.  Each process
calculates the time until the task will next be run, calls timer:sleep/1
for that duration, runs the task, and repeats.

There is no configuration file, instead, crone is started with a list of
tasks to schedule, e.g.:

  crone:start([
                {{daily, {every, {5 min}, {between, {8, am}, {5, pm}}}},
                 {funky_db, dump_to_file, [my_db, "report.txt"]}},
                {{daily, [{1, pm}, {4, 30, am}]},
                 {funky_db, rotate_log, ["foo.log"]}},
                {{weekly, sun, {5, am}},
                 {os, cmd, ["backup important-files"]}},
                {{monthly, 1, {2, am}},
                 {funky_db, monthly_maintenance, []}}
              ]).

It raises the question: just how large can the argument to timer:sleep/1
be?  Scheduling a task on a monthly basis means sleeping for potentially
hundreds of hours (that is, billions of milliseconds.)  How much
inaccuracy should be expected to creep in over such a long wait?

Anyway, if I get some positive feedback on this, I'll submit it to User
Contributions... :)

-Chris
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: crone.erl
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20020704/b801861e/attachment.ksh>


More information about the erlang-questions mailing list