summaryrefslogtreecommitdiffstats
path: root/sms-service/src
diff options
context:
space:
mode:
authorKiran Kamineni <kiran.k.kamineni@intel.com>2018-10-30 12:16:49 -0700
committerKiran Kamineni <kiran.k.kamineni@intel.com>2018-10-30 12:16:55 -0700
commit30840d4634d68d6536bfef1e169e8f8376779d7b (patch)
treeef562b3c18278b332377ebcb539779893c2a21ff /sms-service/src
parentede2e910db50176c9970159cf4f60387d4ee4d93 (diff)
Add a simple Retry to preload
We are seeing in some environments that preload gets a connection refused error. Preload should retry before giving up in such cases. Currently default retry is 5 times after a wait of 5 secs each. Issue-ID: AAF-596 Change-Id: I06e1869374116d777a5dae3fccc72a35e793c6c9 Signed-off-by: Kiran Kamineni <kiran.k.kamineni@intel.com>
Diffstat (limited to 'sms-service/src')
-rw-r--r--sms-service/src/preload/preload.go29
1 files changed, 25 insertions, 4 deletions
diff --git a/sms-service/src/preload/preload.go b/sms-service/src/preload/preload.go
index 7e54fb8..9e9b987 100644
--- a/sms-service/src/preload/preload.go
+++ b/sms-service/src/preload/preload.go
@@ -76,6 +76,7 @@ type smsClient struct {
//In seconds
Timeout int
CaCertPath string
+ RetryCount int
httpClient *http.Client
}
@@ -260,17 +261,36 @@ func (c *smsClient) uploadToSMS(data DataJSON) error {
fmt.Println("Uploading data...")
for _, d := range ldata {
- err := c.createDomain(d.Name)
+ var err error
+ for i := 0; i < c.RetryCount; i++ {
+ err = c.createDomain(d.Name)
+ if err != nil {
+ fmt.Println(pkgerrors.Cause(err))
+ fmt.Println("Retrying...")
+ time.Sleep(5 * time.Second)
+ } else {
+ break
+ }
+ }
if err != nil {
return pkgerrors.Cause(err)
}
for _, s := range d.Secrets {
- err = c.createSecret(d.Name, s.Name, s.Values)
- if err != nil {
- return pkgerrors.Cause(err)
+ for i := 0; i < c.RetryCount; i++ {
+ err = c.createSecret(d.Name, s.Name, s.Values)
+ if err != nil {
+ fmt.Println(pkgerrors.Cause(err))
+ fmt.Println("Retrying...")
+ time.Sleep(5 * time.Second)
+ } else {
+ break
+ }
}
}
+ if err != nil {
+ return pkgerrors.Cause(err)
+ }
}
return nil
@@ -310,6 +330,7 @@ func main() {
Timeout: 30,
BaseURL: serviceURL,
CaCertPath: *cacert,
+ RetryCount: 5,
}
client.init()