changeset 1000:14425e35e3c2 persistent-import-queue

Wait with start of import queue until configuration is fully loaded.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 22 Oct 2018 17:16:02 +0200
parents 60ca5bd3e326
children e2860eff5d03
files cmd/gemma/main.go pkg/config/config.go pkg/imports/queue.go
diffstat 3 files changed, 24 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/cmd/gemma/main.go	Mon Oct 22 16:55:05 2018 +0200
+++ b/cmd/gemma/main.go	Mon Oct 22 17:16:02 2018 +0200
@@ -31,6 +31,8 @@
 
 func start(cmd *cobra.Command, args []string) {
 
+	config.Ready()
+
 	web, err := filepath.Abs(config.Web())
 	if err != nil {
 		log.Fatalf("error: %v\n", err)
--- a/pkg/config/config.go	Mon Oct 22 16:55:05 2018 +0200
+++ b/pkg/config/config.go	Mon Oct 22 17:16:02 2018 +0200
@@ -156,7 +156,26 @@
 	str("proxy-prefix", "", `URL prefix of proxy. Defaults to "http://${web-host}:${web-port}"`)
 
 	str("tmp-dir", "", "Temp directory of gemma server. Defaults to system temp directory.")
+}
 
+var (
+	configCond  = sync.NewCond(new(sync.Mutex))
+	configReady bool
+)
+
+func Ready() {
+	configCond.L.Lock()
+	defer configCond.L.Unlock()
+	configReady = true
+	configCond.Broadcast()
+}
+
+func WaitReady() {
+	configCond.L.Lock()
+	defer configCond.L.Unlock()
+	for !configReady {
+		configCond.Wait()
+	}
 }
 
 func initConfig() {
--- a/pkg/imports/queue.go	Mon Oct 22 16:55:05 2018 +0200
+++ b/pkg/imports/queue.go	Mon Oct 22 17:16:02 2018 +0200
@@ -9,6 +9,7 @@
 	"sync"
 
 	"gemma.intevation.de/gemma/pkg/auth"
+	"gemma.intevation.de/gemma/pkg/config"
 )
 
 type (
@@ -219,6 +220,7 @@
 }
 
 func importLoop() {
+	config.WaitReady()
 	for {
 		queueCond.L.Lock()
 
@@ -259,7 +261,7 @@
 		if errDo != nil {
 			feedback.Error("error do: %v\n", errDo)
 		}
-		errCleanup := survive(job.CleanUp)
+		errCleanup := survive(job.CleanUp)()
 		if errCleanup != nil {
 			feedback.Error("error cleanup: %v\n", errCleanup)
 		}