-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: refactor Fetcher interface used for downloading migrations (#8728)
* feat: refactor Fetcher interface used for downloading migrations * feat: add RetryFetcher for migration downloads * feat: 3 retries for each HTTP migration download (cherry picked from commit b1ffc87)
- Loading branch information
1 parent
3620268
commit 0ce8607
Showing
10 changed files
with
83 additions
and
44 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package migrations | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
) | ||
|
||
type RetryFetcher struct { | ||
Fetcher | ||
MaxTries int | ||
} | ||
|
||
var _ Fetcher = (*RetryFetcher)(nil) | ||
|
||
func (r *RetryFetcher) Fetch(ctx context.Context, filePath string) ([]byte, error) { | ||
var lastErr error | ||
for i := 0; i < r.MaxTries; i++ { | ||
out, err := r.Fetcher.Fetch(ctx, filePath) | ||
if err == nil { | ||
return out, nil | ||
} | ||
|
||
if ctx.Err() != nil { | ||
return nil, ctx.Err() | ||
} | ||
lastErr = err | ||
} | ||
return nil, fmt.Errorf("exceeded number of retries. last error was %w", lastErr) | ||
} | ||
|
||
func (r *RetryFetcher) Close() error { | ||
return r.Fetcher.Close() | ||
} |
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