cron-0.2.2: Cron datatypes and Attoparsec parser

Copyright(c) Michael Xavier 2012
LicenseMIT
MaintainerMichael Xavier <michael@michaelxavier.net>
Portabilityportable
Safe HaskellSafe-Inferred
LanguageHaskell98

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

Synopsis

Documentation

data CronSchedule Source

Specification for a cron expression

Constructors

CronSchedule 

Fields

minute :: MinuteSpec

Which minutes to run. First field in a cron specification.

hour :: HourSpec

Which hours to run. Second field in a cron specification.

dayOfMonth :: DayOfMonthSpec

Which days of the month to run. Third field in a cron specification.

month :: MonthSpec

Which months to run. Fourth field in a cron specification.

dayOfWeek :: DayOfWeekSpec

Which days of the week to run. Fifth field in a cron specification.

newtype Crontab Source

Crontab file, omitting comments.

Constructors

Crontab [CrontabEntry] 

Instances

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

schedule :: CronSchedule
 
command :: Text
 
EnvVariable 

Fields

varName :: Text
 
varValue :: Text
 

data MinuteSpec Source

Minutes field of a cron expression

Constructors

Minutes CronField 

data HourSpec Source

Hours field of a cron expression

Constructors

Hours CronField 

Instances

data MonthSpec Source

Month field of a cron expression

Constructors

Months CronField 

data DayOfMonthSpec Source

Day of month field of a cron expression

Constructors

DaysOfMonth CronField 

data DayOfWeekSpec Source

Day of week field of a cron expression

Constructors

DaysOfWeek CronField 

data CronField Source

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.

yearly :: CronSchedule Source

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 * *

daily :: CronSchedule Source

Shorthand for every day at midnight. Parsed with @daily, 0 0 * * *

weekly :: CronSchedule Source

Shorthand for every sunday at midnight. Parsed with @weekly, 0 0 * * 0

hourly :: CronSchedule Source

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.