- -- Execute run_twat on each username in a new thread.
- let run_twat_curried = run_twat cfg message
- _ <- mapM (forkIO . run_twat_curried) usernames
-
- _ <- forever $ do
- -- This thread (the one executing main) doesn't do anything,
- -- but when it terminates, so do all the threads we forked.
- -- As a result, we need to keep this thread on life support.
- thread_sleep (heartbeat cfg)
-
- return ()
-
-
--- | A debugging tool that will parse, print, and email a single
--- status (given by its id).
-twat_single_status :: Cfg -> Integer -> (Maybe Message) -> IO ()
-twat_single_status cfg the_status_id maybe_message = do
- xmldata <- get_status the_status_id
-
- -- Parsing an empty result can blow up. Just pretend there are
- -- no new statuses in that case.
- let statuses = case xmldata of
- Just xml -> parse_status xml
- Nothing -> []
-
- case (length statuses) of
- 0 -> do
- putStrLn "No statuses returned."
- return ()
- _ -> do
- _ <- mapM (putStrLn . pretty_print) statuses
-
- case maybe_message of
- Nothing -> do
- putStrLn "No message object given."
- return ()
- Just message -> do
- default_date <- rfc822_now
- let messages = map (message_from_status message (default_date)) statuses
- sendmail_results <- mapM sendmail' messages
- _ <- mapM print_sendmail_result sendmail_results
- return ()
- where
- sendmail' = sendmail (sendmail_path cfg)
\ No newline at end of file
+ where
+ -- | A exception handler around full_daemonize. If full_daemonize
+ -- doesn't work, we report the error and crash. This is fine; we
+ -- only need the program to be resilient once it actually starts.
+ --
+ try_daemonize :: Cfg -> IO () -> IO ()
+ try_daemonize cfg program =
+ catchIOError
+ (full_daemonize cfg program)
+ (\e -> do
+ hPutStrLn stderr ("ERROR: " ++ (show e))
+ throw e)