2012-09-06 18:56:04 +00:00
|
|
|
{- git-annex assistant daemon status thread
|
|
|
|
-
|
|
|
|
- Copyright 2012 Joey Hess <joey@kitenet.net>
|
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
|
|
|
module Assistant.Threads.DaemonStatus where
|
|
|
|
|
|
|
|
import Assistant.Common
|
|
|
|
import Assistant.DaemonStatus
|
|
|
|
import Utility.ThreadScheduler
|
|
|
|
import Utility.NotificationBroadcaster
|
|
|
|
|
|
|
|
{- This writes the daemon status to disk, when it changes, but no more
|
|
|
|
- frequently than once every ten minutes.
|
|
|
|
-}
|
2012-10-29 06:21:04 +00:00
|
|
|
daemonStatusThread :: NamedThread
|
2013-01-26 06:09:33 +00:00
|
|
|
daemonStatusThread = namedThread "DaemonStatus" $ do
|
2012-10-29 06:21:04 +00:00
|
|
|
notifier <- liftIO . newNotificationHandle
|
2012-10-30 18:44:18 +00:00
|
|
|
=<< changeNotifier <$> getDaemonStatus
|
2012-09-06 18:56:04 +00:00
|
|
|
checkpoint
|
2012-10-29 06:21:04 +00:00
|
|
|
runEvery (Seconds tenMinutes) <~> do
|
|
|
|
liftIO $ waitNotification notifier
|
2012-09-06 18:56:04 +00:00
|
|
|
checkpoint
|
2012-10-29 06:21:04 +00:00
|
|
|
where
|
|
|
|
checkpoint = do
|
|
|
|
file <- liftAnnex $ fromRepo gitAnnexDaemonStatusFile
|
2012-10-30 18:44:18 +00:00
|
|
|
liftIO . writeDaemonStatusFile file =<< getDaemonStatus
|