Copyright | (c) Andrew Rademacher 2014 |
---|---|
License | MIT |
Maintainer | Andrew Rademacher <andrewrademacher@gmail.com> |
Portability | portable |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
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"
Synopsis
- data Job = Job CronSchedule (IO ())
- forkJob :: Job -> IO ThreadId
- newtype ScheduleError = ParseError String
- type Schedule = ScheduleT Identity
- newtype ScheduleT m a = ScheduleT {
- unSchedule :: StateT Jobs (ExceptT ScheduleError m) a
- class MonadSchedule m where
- runSchedule :: Schedule a -> Either ScheduleError (a, [Job])
- runScheduleT :: ScheduleT m a -> m (Either ScheduleError (a, [Job]))
- execSchedule :: Schedule () -> IO [ThreadId]
Documentation
Scheduling Monad
Job CronSchedule (IO ()) |
forkJob :: Job -> IO ThreadId Source #
Start a job-runner thread that runs a job at appropriate intervals. Each time it is run, a new thread is forked for it, meaning that a single exception does not take down the scheduler.
newtype ScheduleError Source #
Instances
Show ScheduleError Source # | |
Defined in System.Cron.Schedule showsPrec :: Int -> ScheduleError -> ShowS # show :: ScheduleError -> String # showList :: [ScheduleError] -> ShowS # | |
Monad m => MonadError ScheduleError (ScheduleT m) Source # | |
Defined in System.Cron.Schedule throwError :: ScheduleError -> ScheduleT m a # catchError :: ScheduleT m a -> (ScheduleError -> ScheduleT m a) -> ScheduleT m a # |
newtype ScheduleT m a Source #
ScheduleT | |
|
Instances
Monad m => MonadError ScheduleError (ScheduleT m) Source # | |
Defined in System.Cron.Schedule throwError :: ScheduleError -> ScheduleT m a # catchError :: ScheduleT m a -> (ScheduleError -> ScheduleT m a) -> ScheduleT m a # | |
Monad m => Applicative (ScheduleT m) Source # | |
Defined in System.Cron.Schedule | |
Functor m => Functor (ScheduleT m) Source # | |
Monad m => Monad (ScheduleT m) Source # | |
Monad m => MonadSchedule (ScheduleT m) Source # | |
class MonadSchedule m where Source #
runSchedule :: Schedule a -> Either ScheduleError (a, [Job]) Source #
runScheduleT :: ScheduleT m a -> m (Either ScheduleError (a, [Job])) Source #
execSchedule :: Schedule () -> IO [ThreadId] Source #
Schedule all of the jobs to run at appropriate intervals. Each job that is launched gets a scheduling thread to itself. Each time a scheduling thread launches a job, the job is forked onto a new thread. This means that if a job throws an excpetion in IO, its thread will be killed, but it will continue to be scheduled in the future.