forked from forgejo/forgejo
Sleep longer if request speed is over github limitation (#9335)
* Sleep longer if request speed is over github limitation * improve code * remove unused code * fix lint * Use github's rate limit remain value to determine how long to sleep * Save reset time when finished github api request * fix bug * fix lint * Add context.Context for sleep * fix test * improve code * fix bug and lint * fix import order
This commit is contained in:
parent
d1a49977b0
commit
ffc904b1e0
8 changed files with 86 additions and 16 deletions
|
@ -6,6 +6,7 @@
|
|||
package base
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"code.gitea.io/gitea/modules/structs"
|
||||
|
@ -13,6 +14,7 @@ import (
|
|||
|
||||
// Downloader downloads the site repo informations
|
||||
type Downloader interface {
|
||||
SetContext(context.Context)
|
||||
GetRepoInfo() (*Repository, error)
|
||||
GetTopics() ([]string, error)
|
||||
GetMilestones() ([]*Milestone, error)
|
||||
|
@ -30,6 +32,10 @@ type DownloaderFactory interface {
|
|||
GitServiceType() structs.GitServiceType
|
||||
}
|
||||
|
||||
var (
|
||||
_ Downloader = &RetryDownloader{}
|
||||
)
|
||||
|
||||
// RetryDownloader retry the downloads
|
||||
type RetryDownloader struct {
|
||||
Downloader
|
||||
|
@ -46,6 +52,11 @@ func NewRetryDownloader(downloader Downloader, retryTimes, retryDelay int) *Retr
|
|||
}
|
||||
}
|
||||
|
||||
// SetContext set context
|
||||
func (d *RetryDownloader) SetContext(ctx context.Context) {
|
||||
d.Downloader.SetContext(ctx)
|
||||
}
|
||||
|
||||
// GetRepoInfo returns a repository information with retry
|
||||
func (d *RetryDownloader) GetRepoInfo() (*Repository, error) {
|
||||
var (
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue