1d0b692198
When a page is loaded, the javascript requests an notification url, and does long polling on the url to be informed of changes. But if a change occured before the notification url was requested, it would not be notified of that change, and so the page display would not update. I fixed this by *always* updating the page display after it gets the notification url. This is extra work, but the overhead is not noticable in the other overhead of loading a page. (A nicer way would be to somehow record the version of a page initially loaded, and then compare it with the current version when getting the notification url, and only force an update if it's changed. But getting the "version" of the different parts of the page that use long polling is difficult.)
29 lines
858 B
Haskell
29 lines
858 B
Haskell
{- 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.
|
|
-}
|
|
daemonStatusThread :: NamedThread
|
|
daemonStatusThread = namedThread "DaemonStatus" $ do
|
|
notifier <- liftIO . newNotificationHandle False
|
|
=<< changeNotifier <$> getDaemonStatus
|
|
checkpoint
|
|
runEvery (Seconds tenMinutes) <~> do
|
|
liftIO $ waitNotification notifier
|
|
checkpoint
|
|
where
|
|
checkpoint = do
|
|
file <- liftAnnex $ fromRepo gitAnnexDaemonStatusFile
|
|
liftIO . writeDaemonStatusFile file =<< getDaemonStatus
|