-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
130 additions
and
90 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
- Update documentation/examples | ||
- Add bqtail docker image | ||
- Add conditional action | ||
- Integrate with authly | ||
- Integrate with authly |
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 |
---|---|---|
@@ -1 +1 @@ | ||
2.0.2 | ||
2.0.3 |
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,69 @@ | ||
package base | ||
|
||
import ( | ||
"github.com/viant/bqtail/shared" | ||
"github.com/viant/toolbox" | ||
"math/rand" | ||
"os" | ||
"time" | ||
) | ||
|
||
//Retry represents abstraction holding sleep duration between retries (back-off) | ||
type Retry struct { | ||
Count int | ||
Initial time.Duration | ||
Max time.Duration | ||
Multiplier float64 | ||
duration time.Duration | ||
} | ||
|
||
// Pause returns the next time.Duration that the caller should use to backoff. | ||
func (b *Retry) Pause() time.Duration { | ||
if b.Initial == 0 { | ||
b.Initial = time.Second | ||
} | ||
if b.duration == 0 { | ||
b.duration = b.Initial | ||
} | ||
if b.Max == 0 { | ||
b.Max = 30 * time.Second | ||
} | ||
if b.Multiplier < 1 { | ||
b.Multiplier = 2 | ||
} | ||
|
||
rnd := rand.New(rand.NewSource(time.Now().UnixNano())) | ||
result := time.Duration(1 + rnd.Int63n(int64(b.duration))) | ||
b.duration = time.Duration(float64(b.duration) * b.Multiplier) | ||
if b.duration > b.Max { | ||
b.duration = b.Max | ||
} | ||
return result | ||
} | ||
|
||
//NewRetry creates a retry | ||
func NewRetry() *Retry { | ||
return &Retry{} | ||
} | ||
|
||
//RunWithRetries run with retries | ||
func RunWithRetries(f func() error) (err error) { | ||
maxRetries := GetMaxRetries() | ||
retry := NewRetry() | ||
for i := 0; i < maxRetries; i++ { | ||
err = f() | ||
if !IsRetryError(err) { | ||
return err | ||
} | ||
time.Sleep(retry.Pause()) | ||
} | ||
return err | ||
} | ||
|
||
func GetMaxRetries() int { | ||
maxRetries := toolbox.AsInt(os.Getenv(shared.MaxRetriesEnvKey)) | ||
if maxRetries == 0 { | ||
maxRetries = shared.MaxRetries | ||
} | ||
return maxRetries | ||
} |
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
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