mirror of
https://github.com/quantum9Innovation/suntheme.git
synced 2024-11-25 01:43:50 -08:00
f22d715b8e
introduce Workers, Cache modules and shuffle around some existing functions
26 lines
879 B
Haskell
26 lines
879 B
Haskell
module Workers where
|
|
|
|
import Time (chooseActivation, activateOnSunrise, sunriseNow, sunsetNow)
|
|
import Cache (finish, readCache)
|
|
import Sugar (crash, exec)
|
|
|
|
prepareScripts :: (Double, Double) -> IO ()
|
|
prepareScripts (lat, lon) = do
|
|
sunriseTime <- sunriseNow lat lon
|
|
sunsetTime <- sunsetNow lat lon
|
|
lightMode <- activateOnSunrise sunriseTime sunsetTime
|
|
_ <- chooseActivation lightMode sunriseTime sunsetTime
|
|
queue <- exec "atq" noQueue
|
|
finish queue
|
|
where
|
|
noQueueMsg = "Scheduled process could not be retrieved (try rerunning if 'atq' fails)"
|
|
noQueue _ = print noQueueMsg >> return ""
|
|
|
|
backupRunner :: IO ()
|
|
backupRunner = do
|
|
contents <- readCache
|
|
case contents of
|
|
Nothing -> do
|
|
putStrLn "Failed to read cache after IP location failed"
|
|
crash
|
|
Just (lat, lon, _) -> prepareScripts (lat, lon)
|