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
|
|
|
|
-
|
2015-01-21 16:50:09 +00:00
|
|
|
- Copyright 2012 Joey Hess <id@joeyh.name>
|
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
|
|
|
-
|
2019-03-13 19:48:14 +00:00
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
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
|
|
|
-}
|
|
|
|
|
|
|
|
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
|
2013-10-08 15:48:28 +00:00
|
|
|
import Logs
|
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 Logs.UUID
|
|
|
|
import Logs.Trust
|
|
|
|
import Logs.PreferredContent
|
|
|
|
import Logs.Group
|
2014-01-20 20:47:56 +00:00
|
|
|
import Logs.NumCopies
|
2020-05-27 15:54:39 +00:00
|
|
|
import Remote.List.Util
|
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 qualified Git.LsTree as LsTree
|
2016-01-01 19:56:24 +00:00
|
|
|
import Git.Types
|
2013-10-17 18:51:39 +00:00
|
|
|
import Git.FilePath
|
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 qualified Annex.Branch
|
2019-05-14 18:01:09 +00:00
|
|
|
import Annex.FileMatcher
|
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 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" :
|
2019-12-05 19:10:23 +00:00
|
|
|
map (fromRawFilePath . fst)
|
|
|
|
(S.toList changedconfigs)
|
2012-10-29 15:40:22 +00:00
|
|
|
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. -}
|
2019-12-05 19:10:23 +00:00
|
|
|
type Configs = S.Set (RawFilePath, Sha)
|
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
|
|
|
|
|
|
|
{- All git-annex's config files, and actions to run when they change. -}
|
2019-12-05 19:10:23 +00:00
|
|
|
configFilesActions :: [(RawFilePath, Assistant ())]
|
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
|
|
|
configFilesActions =
|
2019-01-01 19:39:45 +00:00
|
|
|
[ (uuidLog, void $ liftAnnex uuidDescMapLoad)
|
2020-05-27 15:54:39 +00:00
|
|
|
, (remoteLog, void $ liftAnnex remotesChanged)
|
2013-10-08 15:48:28 +00:00
|
|
|
, (trustLog, void $ liftAnnex trustMapLoad)
|
|
|
|
, (groupLog, void $ liftAnnex groupMapLoad)
|
2014-01-21 20:08:19 +00:00
|
|
|
, (numcopiesLog, void $ liftAnnex globalNumCopiesLoad)
|
2013-10-08 15:48:28 +00:00
|
|
|
, (scheduleLog, void updateScheduleLog)
|
2014-03-29 19:20:55 +00:00
|
|
|
-- Preferred and required content settings depend on most of the
|
|
|
|
-- other configs, so will be reloaded whenever any configs change.
|
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
|
|
|
, (preferredContentLog, noop)
|
2014-03-29 19:20:55 +00:00
|
|
|
, (requiredContentLog, noop)
|
2014-03-29 18:46:27 +00:00
|
|
|
, (groupPreferredContentLog, noop)
|
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
|
|
|
reloadConfigs :: Configs -> Assistant ()
|
|
|
|
reloadConfigs changedconfigs = do
|
2013-10-08 15:48:28 +00:00
|
|
|
sequence_ as
|
2019-05-14 18:01:09 +00:00
|
|
|
void $ liftAnnex $ preferredRequiredMapsLoad preferredContentTokens
|
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. -}
|
2013-10-03 02:59:07 +00:00
|
|
|
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
|
2019-12-05 19:10:23 +00:00
|
|
|
files = map (fromRawFilePath . fst) configFilesActions
|
2019-12-09 17:49:05 +00:00
|
|
|
extract treeitem = (getTopFilePath $ LsTree.file treeitem, LsTree.sha treeitem)
|