changeset 3582:317d176ef38c

GM import: Try three times when timeouts happen on SOAP service. Increase SOAP timeout to 3 minutes.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 03 Jun 2019 18:24:35 +0200
parents 9114097964d7
children 391afcc961a2
files example_conf.toml pkg/config/config.go pkg/imports/gm.go
diffstat 3 files changed, 16 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/example_conf.toml	Mon Jun 03 18:07:57 2019 +0200
+++ b/example_conf.toml	Mon Jun 03 18:24:35 2019 +0200
@@ -72,7 +72,7 @@
 # ----------------------------------------------------------------------
 # SOAP/XML-based importer setup:
 
-# soap-timeout = "1m"
+# soap-timeout = "3m"
 
 # Schema for "Testclient imports"
 # schema-dirs = "$PATH_TO_SCHEMATA"
--- a/pkg/config/config.go	Mon Jun 03 18:07:57 2019 +0200
+++ b/pkg/config/config.go	Mon Jun 03 18:24:35 2019 +0200
@@ -282,7 +282,7 @@
 
 	str("published-config", "", "path to a config file served to client.")
 
-	d("soap-timeout", time.Minute, "Timeout till a SOAP request is canceled.")
+	d("soap-timeout", 3*time.Minute, "Timeout till a SOAP request is canceled.")
 }
 
 var (
--- a/pkg/imports/gm.go	Mon Jun 03 18:07:57 2019 +0200
+++ b/pkg/imports/gm.go	Mon Jun 03 18:24:35 2019 +0200
@@ -19,6 +19,7 @@
 	"context"
 	"database/sql"
 	"fmt"
+	"log"
 	"sort"
 	"strings"
 	"time"
@@ -177,9 +178,21 @@
 			Message_type: &mt,
 		}
 
+		const maxTries = 3
+
+		tries := 0
+
+	again:
 		resp, err := client.Get_messages(req)
+
 		if err != nil {
-			return nil, err
+			if t, ok := err.(interface{ Timeout() bool }); ok && t.Timeout() && tries < maxTries {
+				log.Println("warn: NtS SOAP request timed out. Trying again.")
+				tries++
+				goto again
+			}
+			return nil, fmt.Errorf(
+				"Error requesting NtS service: %v", err)
 		}
 
 		result := resp.Result_message