aboutsummaryrefslogtreecommitdiff
path: root/Assistant/NamedThread.hs
blob: 4622f874288d4638457c5a05c5e41b51a9e342c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
{- git-annex assistant named threads.
 -
 - Copyright 2012 Joey Hess <joey@kitenet.net>
 -
 - Licensed under the GNU GPL version 3 or higher.
 -}

module Assistant.NamedThread where

import Assistant.Common
import Assistant.DaemonStatus
import Assistant.Alert

import qualified Control.Exception as E

runNamedThread :: NamedThread -> Assistant ()
runNamedThread (NamedThread name a) = do
	d <- getAssistant id
	liftIO . go $ d { threadName = name }
  where
	go d = do
		r <- E.try (runAssistant a d) :: IO (Either E.SomeException ())
		case r of
			Right _ -> noop
			Left e -> do
				let msg = unwords [name, "crashed:", show e]
				hPutStrLn stderr msg
				-- TODO click to restart
				flip runAssistant d $ void $
					addAlert $ warningAlert name msg