| Copyright | (c) Michael Xavier 2012 |
|---|---|
| License | MIT |
| Maintainer | Michael Xavier <michael@michaelxavier.net> |
| Portability | portable |
| Safe Haskell | Safe-Inferred |
| Language | Haskell98 |
System.Cron
Description
Toplevel module for Cron specifying a cron schedule and several convenience functions for dealing with cron schedules
import Control.Concurrent
import Control.Monad
import Data.Time.Clock
import System.Cron
main :: IO ()
main = forever $ do
now <- getCurrentTime
when (scheduleMatches schedule now) doWork
putStrLn "sleeping"
threadDelay 100000
where doWork = putStrLn "Time to work"
schedule = hourly- data CronSchedule = CronSchedule {}
- newtype Crontab = Crontab [CrontabEntry]
- data CrontabEntry
- = CommandEntry {
- schedule :: CronSchedule
- command :: Text
- | EnvVariable { }
- = CommandEntry {
- data MinuteSpec = Minutes CronField
- data HourSpec = Hours CronField
- data MonthSpec = Months CronField
- data DayOfMonthSpec = DaysOfMonth CronField
- data DayOfWeekSpec = DaysOfWeek CronField
- data CronField
- yearly :: CronSchedule
- monthly :: CronSchedule
- daily :: CronSchedule
- weekly :: CronSchedule
- hourly :: CronSchedule
- everyMinute :: CronSchedule
- scheduleMatches :: CronSchedule -> UTCTime -> Bool
Documentation
data CronSchedule Source
Specification for a cron expression
Constructors
| CronSchedule | |
Fields
| |
Instances
Crontab file, omitting comments.
Constructors
| Crontab [CrontabEntry] |
data CrontabEntry Source
Essentially a line in a crontab file. It is either a schedule with a command after it or setting an environment variable (e.g. FOO=BAR)
Constructors
| CommandEntry | |
Fields
| |
| EnvVariable | |
Instances
Hours field of a cron expression
Month field of a cron expression
data DayOfMonthSpec Source
Day of month field of a cron expression
Constructors
| DaysOfMonth CronField |
Instances
data DayOfWeekSpec Source
Day of week field of a cron expression
Constructors
| DaysOfWeek CronField |
Instances
Individual field of a cron expression.
Constructors
| Star | Matches anything |
| SpecificField Int | Matches a specific value (e.g. 1) |
| RangeField Int Int | Matches a range of values (e.g. 1-3) |
| ListField [CronField] | Matches a list of expressions. Recursive lists are invalid and the parser will never produce them. |
| StepField CronField Int | Matches a stepped expression, e.g. (*/2). Recursive steps or stepped lists are invalid and the parser will never produce them. |
Shorthand for every January 1st at midnight. Parsed with @yearly, 0 0 1 1 *
monthly :: CronSchedule Source
Shorthand for every 1st of the month at midnight. Parsed with @monthly, 0 0 1 * *
Shorthand for every day at midnight. Parsed with @daily, 0 0 * * *
Shorthand for every sunday at midnight. Parsed with @weekly, 0 0 * * 0
Shorthand for every hour on the hour. Parsed with @hourly, 0 * * * *
everyMinute :: CronSchedule Source
Shorthand for an expression that always matches. Parsed with * * * * *
scheduleMatches :: CronSchedule -> UTCTime -> Bool Source
Determines if the given time is matched by the given schedule. A periodical task would use this to determine if an action needs to be performed at the current time or not.