cron

Cron datatypes and Attoparsec parser http://github.com/michaelxavier/cron

Version on this page:0.4.1.2
LTS Haskell 8.20:0.5.0
Stackage Nightly 2017-06-28:0.5.0
Latest on Hackage:0.5.0
MIT licensed and maintained by Michael Xavier

Module documentation for 0.4.1.2

cron

Build Status

Cron data structure and Attoparsec parser for Haskell. The idea is to embed it in larger systems which want to roll their own scheduled tasks in a format that people are used to.

System.Cron is where all the interesting datatypes live. You will also find scheduleMatches, which you can use to compare a time against a CronSchedule to see if an action needs to be performed. System.Cron.Parser is where you will find the parsers cronSchedule, crontabEntry and cronTab. To parse individual schedules up to full crontab files. System.Cron.Descrive is where you will find the describe function for creating human-readable strings from cron schedules, as well as any options to control how the description is created.

To do anything, you'll need to install cabal-dev with cabal.

To build, run:

make

To run tests, run:

make test

If you have inotify-tools, run this to run tests continuously.

make autotest

To generate docs:

make docs

Scheduler

Cron offers a scheduling monad which can be found in System.Cron.Schedule. This monad transform allows you to declare a set of jobs (of the type IO ()) that will be executed at intervals defined by cron strings.

main :: IO ()
main = do
    ...
    tids <- execSchedule $ do
        addJob job1 "* * * * *"
        addJob job2 "0 * * * *"
    print tids
    ...

job1 :: IO ()
job1 = putStrLn "Job 1"

job2 :: IO ()
job2 = putStrLn "Job 2"

Describe

main :: IO ()
main = do
  let Right cs1 = parseCronSchedule "*/2 * 3 * 4,5,6"
  print $ describe defaultOpts cs1

  let Right cs2 = parseCronSchedule "*/2 12 3 * 4,5,6"
  print $ describe (twentyFourHourFormat <> verbose) cs2

Contributors

Changes

# 0.5.0
* Add System.Cron.Describe which describes cron schedules in words (English only for now). Big thanks to Joe Canero for this feature!
# 0.4.2
* Drop dependency on derive in tests.
* Add some Generic and Typeable instances.
# 0.4.1.1
* Bug fix for checking nextMatch where either the day of month or day of week fields were a singleton list of star.
# 0.4.1.1
* Fix test suite for Stackage.
# 0.4.1
* Compatibility release to get cron building with GHC < 7.10 again.
# 0.4.0
* Various type changes to make it impossible to construct invalid cron schedules.
* Add nextMatch function for non-polling based schedulers.
# 0.3.2
* Add test files to dist
# 0.3.1
* Fix bug that caused some range schedules to not fire at the correct time. See https://github.com/MichaelXavier/cron/issues/18
# 0.3.0
* MTL compatibility updates.
# 0.2.6
* Package test files
# 0.2.5
* GHC 7.10 support
# 0.2.4
* Bugfixes for new task runner feature
# 0.2.3
* Add new in-process task runner feature. Credit to @AndrewRademacher
# 0.2.2
* Fix edge case when day of month and day of week are both specified. Credit to @joelwilliamson
# 0.2.1
* Fix day of week bug. Credit to @meteogrid
# 0.1.2
* Relax dependency on text to allow 1.0
comments powered byDisqus