-
Notifications
You must be signed in to change notification settings - Fork 457
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dev: introduce unified retry SQL and place SQL into 'heredoc'
- Loading branch information
1 parent
7ff23e7
commit 619842e
Showing
12 changed files
with
479 additions
and
47 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright 2019 Altinity Ltd and/or its affiliates. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package util | ||
|
||
import ( | ||
"github.com/golang/glog" | ||
"time" | ||
) | ||
|
||
// Retry | ||
func Retry(tries int, desc string, f func() error) error { | ||
var err error | ||
for try := 1; try <= tries; try++ { | ||
err = f() | ||
if err == nil { | ||
// All ok, no need to retry more | ||
if try > 1 { | ||
// Done, but after some retries, this is not 'clean' | ||
glog.V(1).Infof("attempt %d of %d is finally DONE: %s", try, tries, desc) | ||
} | ||
return nil | ||
} | ||
if try < tries { | ||
// Try failed, need to sleep and retry | ||
seconds := try * 5 | ||
glog.V(1).Infof("attempt %d of %d FAILED, sleep %d sec and retry: %s", try, tries, seconds, desc) | ||
time.Sleep(time.Duration(seconds) * time.Second) | ||
} else { | ||
// On last try no need to wait more | ||
glog.V(1).Infof("all %d attempts FAILED, ABORT retry: %s", tries, desc) | ||
} | ||
} | ||
return err | ||
} |
13 changes: 13 additions & 0 deletions
13
vendor/github.com/MakeNowJust/heredoc/.circleci/config.yml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.