cron 0.2.3 → 0.2.4
raw patch · 2 files changed
+12/−12 lines, 2 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- cron.cabal +2/−1
- src/System/Cron/Schedule.hs +10/−11
cron.cabal view
@@ -1,5 +1,5 @@ Name: cron-Version: 0.2.3+Version: 0.2.4 Description: Cron data structure and Attoparsec parser. The idea is to embed it in larger systems which want to roll their own scheduled tasks in a format that people@@ -59,6 +59,7 @@ text >= 0.11 && < 2, time >= 1.4, transformers >= 0.4+ Ghc-Options: -threaded -rtsopts source-repository head Type: git
src/System/Cron/Schedule.hs view
@@ -99,21 +99,20 @@ forkJob :: Job -> IO ThreadId forkJob (Job s a) = forkIO $ forever $ do- now <- getCurrentTime- findNextMinuteDelay >>= threadDelay- when (scheduleMatches s now) a+ (timeAt, delay) <- findNextMinuteDelay+ threadDelay delay+ when (scheduleMatches s timeAt) a -findNextMinuteDelay :: IO Int+findNextMinuteDelay :: IO (UTCTime, Int) findNextMinuteDelay = do now <- getCurrentTime- let f = formatTime defaultTimeLocale fmtFront now- m = (read (formatTime defaultTimeLocale fmtMinutes now) :: Int) + 1- r = f ++ ":" ++ if length (show m) == 1 then "0" ++ show m else show m- next = readTime defaultTimeLocale fmtRead r :: UTCTime- newNow <- getCurrentTime -- Compensates for the time spent calculating what the next minute is.- let diff = diffUTCTime next newNow+ let f = formatTime defaultTimeLocale fmtFront now+ m = (read (formatTime defaultTimeLocale fmtMinutes now) :: Int) + 1+ r = f ++ ":" ++ if length (show m) == 1 then "0" ++ show m else show m+ next = readTime defaultTimeLocale fmtRead r :: UTCTime+ diff = diffUTCTime next now delay = round (realToFrac (diff * 1000000) :: Double) :: Int- return delay+ return (next, delay) where fmtFront = "%F %H" fmtMinutes = "%M" fmtRead = "%F %H:%M"