Skip to content
This repository has been archived by the owner on Dec 13, 2022. It is now read-only.

Commit

Permalink
remove external library dependency 'backoff'
Browse files Browse the repository at this point in the history
  • Loading branch information
svyotov committed Aug 31, 2020
1 parent 7cc3958 commit 276329d
Showing 1 changed file with 3 additions and 14 deletions.
17 changes: 3 additions & 14 deletions ghbackup/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,8 @@ import (
"log"
"net/http"
"time"

"github.com/cenkalti/backoff"
)

func newExponentialBackOff() *backoff.ExponentialBackOff {
b := backoff.NewExponentialBackOff()
b.InitialInterval = 1 * time.Second
b.MaxElapsedTime = 5 * time.Minute
return b
}

// Run update for the given Config.
func Run(config Config) error {
// Defaults
Expand Down Expand Up @@ -48,17 +39,15 @@ func Run(config Config) error {

// Backup repositories in parallel with exponential-backoff retries
go each(repos, config.Workers, func(r repo) {
eBackoff := newExponentialBackOff()
state, err := config.backup(r)
for {
for _, sleepDuration := range []time.Duration{5, 15, 45, 90, 180, -1} {
if err != nil {
sleepDuration := eBackoff.NextBackOff()
if sleepDuration == backoff.Stop {
if sleepDuration == -1 {
config.Log.Printf("repository %v failed to get cloned: %v", r, err)
break
}
config.Err.Println(err)
time.Sleep(sleepDuration)
time.Sleep(sleepDuration * time.Second)
state, err = config.backup(r)
continue
}
Expand Down

0 comments on commit 276329d

Please sign in to comment.