schedule :: Config -> Nyaa () -> IO ()
schedule cfg ny = do
  setLogHandlers $ cfgLogHandlers cfg
  setLogLevel $ cfgLogLevel cfg
  tid <- myThreadId
  when (cfgCatchSignals cfg) $ do
    installHandler keyboardSignal (Catch $ die tid) (Just fullSignalSet)
    installHandler softwareTermination (Catch $ die tid) (Just fullSignalSet)
    return ()
  case cfgSchedule cfg of
    Once              -> do
      info' "Starting oneshot run..."
      tot <- execute cfg ny
      info' $ "Run completed! " ++ show tot ++ " items accepted."
    (Every n Seconds) -> every n (show n ++ " seconds") $ execute cfg ny
    (Every n Minutes) -> every (n*60) (show n ++ " minutes") $ execute cfg ny
    (Every n Hours)   -> every (n*60*60) (show n ++ " hours") $ execute cfg ny
    (Every n Days)    -> every (n*24*60*60) (show n ++ " days") $ execute cfg ny

-- | Perform an action every n seconds.
schedule :: Config -> Nyaa () -> IO ()
schedule cfg ny = do
  setLogHandlers $ cfgLogHandlers cfg
  setLogLevel $ cfgLogLevel cfg
  tid <- myThreadId
  when (cfgCatchSignals cfg) $ do
    installHandler keyboardSignal (Catch $ die tid) (Just fullSignalSet)
    installHandler softwareTermination (Catch $ die tid) (Just fullSignalSet)
    return ()
  case cfgSchedule cfg of
    Once              -> do
      info' "Starting oneshot run..."
      tot <- execute cfg ny
      info' $ "Run completed! " ++ show tot ++ " items accepted."
    (Every n Seconds) -> every n (show n ++ " seconds") $ execute cfg ny
    (Every n Minutes) -> every (n*60) (show n ++ " minutes") $ execute cfg ny
    (Every n Hours)   -> every (n*60*60) (show n ++ " hours") $ execute cfg ny
    (Every n Days)    -> every (n*24*60*60) (show n ++ " days") $ execute cfg ny

-- | Perform an action every n seconds.
schedule cfg ny = do
  setLogHandlers $ cfgLogHandlers cfg
  setLogLevel $ cfgLogLevel cfg
  tid <- myThreadId
  when (cfgCatchSignals cfg) $ do
    installHandler keyboardSignal (Catch $ die tid) (Just fullSignalSet)
    installHandler softwareTermination (Catch $ die tid) (Just fullSignalSet)
    return ()
  case cfgSchedule cfg of
    Once              -> do
      info' "Starting oneshot run..."
      tot <- execute cfg ny
      info' $ "Run completed! " ++ show tot ++ " items accepted."
    (Every n Seconds) -> every n (show n ++ " seconds") $ execute cfg ny
    (Every n Minutes) -> every (n*60) (show n ++ " minutes") $ execute cfg ny
    (Every n Hours)   -> every (n*60*60) (show n ++ " hours") $ execute cfg ny
    (Every n Days)    -> every (n*24*60*60) (show n ++ " days") $ execute cfg ny

-- | Perform an action every n seconds.