Announcing Saturn, a Haskell library for handling cron schedules

by Taylor Fausak on

I’m happy to announce Saturn, a small Haskell library for handling POSIX cron schedules. It can parse and render schedules, as well as tell you the next time that would match a schedule. And that’s about it.

Motivation

I’ve been using the cron package for a long time. Unfortunately it seems to be unmaintained. I’ve opened pull requests that have gone without any type of response for over a year.

I considered attempting to take over the cron package, but it supports a few features that I didn’t want to support. So instead I shrunk the API to the smallest set that would cover my use cases and pulled that into a new package.

Limitations

Saturn only supports POSIX cron, which might be more limited than you’d expect. Some notable omissions are steps, like */2, and nice day or month names, like MON or JAN.

Also Saturn only supports cron schedules, not entire expressions which are the lines in a crontab file. For my use cases, I only need the schedule. That’s because the main loop for running tasks lives in something else, like a job queue.

Experiments

I developed Saturn using multiple public libraries, which is a relatively new feature in Cabal. The main library (saturn:lib:saturn) exposes the public API. It’s backed by another “internal” library (saturn:lib:unstable) that exposes all the gory details. My intent with this was to try to make the *.Internal module pattern a little more explicit. All of Saturn’s internals are there for you to use, but you have to very explicitly opt into them.

And finally there’s a test library (saturn:lib:spec). This won’t be useful for most people, but it does expose QuickCheck generators for all of Saturn’s types. So if you want to write property tests with cron schedules, this might be useful for you.