[ARVADOS] updated: 2.1.0-1508-g92514990f

Git user git at public.arvados.org
Fri Oct 29 14:07:13 UTC 2021


Summary of changes:
 lib/config/load.go | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)

       via  92514990f5f2698332c237fef954a63e89ab8f75 (commit)
      from  c89fe7089e41c75de4e4d6339855e5768e2ad01c (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit 92514990f5f2698332c237fef954a63e89ab8f75
Author: Lucas Di Pentima <lucas.dipentima at curii.com>
Date:   Fri Oct 29 11:06:46 2021 -0300

    17944: Adds vocabulary file auto-reloader.
    
    Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <lucas.dipentima at curii.com>

diff --git a/lib/config/load.go b/lib/config/load.go
index ee1000d14..8462aa6e8 100644
--- a/lib/config/load.go
+++ b/lib/config/load.go
@@ -17,6 +17,7 @@ import (
 	"strings"
 
 	"git.arvados.org/arvados.git/sdk/go/arvados"
+	"github.com/fsnotify/fsnotify"
 	"github.com/ghodss/yaml"
 	"github.com/imdario/mergo"
 	"github.com/sirupsen/logrus"
@@ -401,6 +402,22 @@ func (ldr *Loader) loadVocabulary(cfg *arvados.Config) error {
 	if cc.API.VocabularyPath == "" {
 		return nil
 	}
+	ldr.Logger.Info("Loading vocabulary")
+	err = ldr.vocabularyFileLoader(cc)
+	if err != nil {
+		return err
+	}
+	go watchVocabulary(ldr.Logger, cc.API.VocabularyPath, func() {
+		ldr.Logger.Info("Reloading vocabulary")
+		err = ldr.vocabularyFileLoader(cc)
+		if err != nil {
+			ldr.Logger.Error("Error reloading vocabulary: %v", err)
+		}
+	})
+	return nil
+}
+
+func (ldr *Loader) vocabularyFileLoader(cc *arvados.Cluster) error {
 	vf, err := os.ReadFile(cc.API.VocabularyPath)
 	if err != nil {
 		return fmt.Errorf("couldn't read vocabulary file %q: %v", cc.API.VocabularyPath, err)
@@ -414,9 +431,43 @@ func (ldr *Loader) loadVocabulary(cfg *arvados.Config) error {
 		return fmt.Errorf("while loading vocabulary file %q: %s", cc.API.VocabularyPath, err)
 	}
 	cc.API.Vocabulary = voc
+	ldr.Logger.Info("Vocabulary loading succeeded")
 	return nil
 }
 
+func watchVocabulary(logger logrus.FieldLogger, vocPath string, fn func()) {
+	watcher, err := fsnotify.NewWatcher()
+	if err != nil {
+		logger.WithError(err).Error("vocabulary fsnotify setup failed")
+		return
+	}
+	defer watcher.Close()
+
+	err = watcher.Add(vocPath)
+	if err != nil {
+		logger.WithError(err).Error("vocabulary file watcher failed")
+		return
+	}
+
+	for {
+		select {
+		case err, ok := <-watcher.Errors:
+			if !ok {
+				return
+			}
+			logger.WithError(err).Warn("vocabulary file watcher error")
+		case _, ok := <-watcher.Events:
+			if !ok {
+				return
+			}
+			for len(watcher.Events) > 0 {
+				<-watcher.Events
+			}
+			fn()
+		}
+	}
+}
+
 func checkKeyConflict(label string, m map[string]string) error {
 	saw := map[string]bool{}
 	for k := range m {

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list