add ConfigMonitor thread
Monitors git-annex branch for changes, which are noticed by the Merger
thread whenever the branch ref is changed (either due to an incoming push,
or a local change), and refreshes cached config values for modified config
files.
Rate limited to run no more often than once per minute. This is important
because frequent git-annex branch changes happen when files are being
added, or transferred, etc.
A primary use case is that, when preferred content changes are made,
and get pushed to remotes, the remotes start honoring those settings.
Other use cases include propigating repository description and trust
changes to remotes, and learning when a remote has added a new special
remote, so the webapp can present the GUI to enable that special remote
locally.
Also added a uuid.log cache. All other config files already had caches.
2012-10-20 20:37:06 +00:00
|
|
|
{- git-annex assistant config monitor thread
|
|
|
|
-
|
|
|
|
- Copyright 2012 Joey Hess <joey@kitenet.net>
|
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
|
|
|
module Assistant.Threads.ConfigMonitor where
|
|
|
|
|
|
|
|
import Assistant.Common
|
|
|
|
import Assistant.BranchChange
|
|
|
|
import Assistant.DaemonStatus
|
2012-10-21 19:50:49 +00:00
|
|
|
import Assistant.Commits
|
add ConfigMonitor thread
Monitors git-annex branch for changes, which are noticed by the Merger
thread whenever the branch ref is changed (either due to an incoming push,
or a local change), and refreshes cached config values for modified config
files.
Rate limited to run no more often than once per minute. This is important
because frequent git-annex branch changes happen when files are being
added, or transferred, etc.
A primary use case is that, when preferred content changes are made,
and get pushed to remotes, the remotes start honoring those settings.
Other use cases include propigating repository description and trust
changes to remotes, and learning when a remote has added a new special
remote, so the webapp can present the GUI to enable that special remote
locally.
Also added a uuid.log cache. All other config files already had caches.
2012-10-20 20:37:06 +00:00
|
|
|
import Utility.ThreadScheduler
|
|
|
|
import Logs.UUID
|
|
|
|
import Logs.Trust
|
|
|
|
import Logs.Remote
|
|
|
|
import Logs.PreferredContent
|
|
|
|
import Logs.Group
|
|
|
|
import Remote.List (remoteListRefresh)
|
|
|
|
import qualified Git.LsTree as LsTree
|
|
|
|
import qualified Annex.Branch
|
|
|
|
|
|
|
|
import qualified Data.Set as S
|
|
|
|
|
|
|
|
{- This thread detects when configuration changes have been made to the
|
|
|
|
- git-annex branch and reloads cached configuration.
|
|
|
|
-
|
|
|
|
- If the branch is frequently changing, it's checked for configuration
|
|
|
|
- changes no more often than once every 60 seconds. On the other hand,
|
|
|
|
- if the branch has not changed in a while, configuration changes will
|
|
|
|
- be detected immediately.
|
|
|
|
-}
|
2012-10-29 15:40:22 +00:00
|
|
|
configMonitorThread :: NamedThread
|
2013-01-26 06:09:33 +00:00
|
|
|
configMonitorThread = namedThread "ConfigMonitor" $ loop =<< getConfigs
|
2012-10-29 15:40:22 +00:00
|
|
|
where
|
|
|
|
loop old = do
|
2012-10-29 23:20:54 +00:00
|
|
|
waitBranchChange
|
2012-10-29 15:40:22 +00:00
|
|
|
new <- getConfigs
|
|
|
|
when (old /= new) $ do
|
|
|
|
let changedconfigs = new `S.difference` old
|
|
|
|
debug $ "reloading config" :
|
|
|
|
map fst (S.toList changedconfigs)
|
|
|
|
reloadConfigs new
|
|
|
|
{- Record a commit to get this config
|
|
|
|
- change pushed out to remotes. -}
|
2012-10-29 23:35:18 +00:00
|
|
|
recordCommit
|
2012-10-30 21:23:42 +00:00
|
|
|
liftIO $ threadDelaySeconds (Seconds 60)
|
2012-10-29 15:40:22 +00:00
|
|
|
loop new
|
add ConfigMonitor thread
Monitors git-annex branch for changes, which are noticed by the Merger
thread whenever the branch ref is changed (either due to an incoming push,
or a local change), and refreshes cached config values for modified config
files.
Rate limited to run no more often than once per minute. This is important
because frequent git-annex branch changes happen when files are being
added, or transferred, etc.
A primary use case is that, when preferred content changes are made,
and get pushed to remotes, the remotes start honoring those settings.
Other use cases include propigating repository description and trust
changes to remotes, and learning when a remote has added a new special
remote, so the webapp can present the GUI to enable that special remote
locally.
Also added a uuid.log cache. All other config files already had caches.
2012-10-20 20:37:06 +00:00
|
|
|
|
|
|
|
{- Config files, and their checksums. -}
|
|
|
|
type Configs = S.Set (FilePath, String)
|
|
|
|
|
|
|
|
{- All git-annex's config files, and actions to run when they change. -}
|
|
|
|
configFilesActions :: [(FilePath, Annex ())]
|
|
|
|
configFilesActions =
|
|
|
|
[ (uuidLog, void $ uuidMapLoad)
|
|
|
|
, (remoteLog, void remoteListRefresh)
|
|
|
|
, (trustLog, void trustMapLoad)
|
|
|
|
, (groupLog, void groupMapLoad)
|
|
|
|
-- Preferred content settings depend on most of the other configs,
|
|
|
|
-- so will be reloaded whenever any configs change.
|
|
|
|
, (preferredContentLog, noop)
|
|
|
|
]
|
|
|
|
|
2012-10-29 15:40:22 +00:00
|
|
|
reloadConfigs :: Configs -> Assistant ()
|
|
|
|
reloadConfigs changedconfigs = do
|
|
|
|
liftAnnex $ do
|
|
|
|
sequence_ as
|
|
|
|
void preferredContentMapLoad
|
add ConfigMonitor thread
Monitors git-annex branch for changes, which are noticed by the Merger
thread whenever the branch ref is changed (either due to an incoming push,
or a local change), and refreshes cached config values for modified config
files.
Rate limited to run no more often than once per minute. This is important
because frequent git-annex branch changes happen when files are being
added, or transferred, etc.
A primary use case is that, when preferred content changes are made,
and get pushed to remotes, the remotes start honoring those settings.
Other use cases include propigating repository description and trust
changes to remotes, and learning when a remote has added a new special
remote, so the webapp can present the GUI to enable that special remote
locally.
Also added a uuid.log cache. All other config files already had caches.
2012-10-20 20:37:06 +00:00
|
|
|
{- Changes to the remote log, or the trust log, can affect the
|
2012-11-13 21:50:54 +00:00
|
|
|
- syncRemotes list. Changes to the uuid log may affect its
|
|
|
|
- display so are also included. -}
|
|
|
|
when (any (`elem` fs) [remoteLog, trustLog, uuidLog]) $
|
2012-10-30 19:39:15 +00:00
|
|
|
updateSyncRemotes
|
2012-10-29 15:40:22 +00:00
|
|
|
where
|
|
|
|
(fs, as) = unzip $ filter (flip S.member changedfiles . fst)
|
|
|
|
configFilesActions
|
|
|
|
changedfiles = S.map fst changedconfigs
|
add ConfigMonitor thread
Monitors git-annex branch for changes, which are noticed by the Merger
thread whenever the branch ref is changed (either due to an incoming push,
or a local change), and refreshes cached config values for modified config
files.
Rate limited to run no more often than once per minute. This is important
because frequent git-annex branch changes happen when files are being
added, or transferred, etc.
A primary use case is that, when preferred content changes are made,
and get pushed to remotes, the remotes start honoring those settings.
Other use cases include propigating repository description and trust
changes to remotes, and learning when a remote has added a new special
remote, so the webapp can present the GUI to enable that special remote
locally.
Also added a uuid.log cache. All other config files already had caches.
2012-10-20 20:37:06 +00:00
|
|
|
|
2012-10-29 15:40:22 +00:00
|
|
|
getConfigs :: Assistant Configs
|
|
|
|
getConfigs = S.fromList . map extract
|
|
|
|
<$> liftAnnex (inRepo $ LsTree.lsTreeFiles Annex.Branch.fullname files)
|
|
|
|
where
|
|
|
|
files = map fst configFilesActions
|
|
|
|
extract treeitem = (LsTree.file treeitem, LsTree.sha treeitem)
|