Skip to content

Commit

Permalink
Fix issue sync rate limit wait
Browse files Browse the repository at this point in the history
  • Loading branch information
juliangiebel committed Nov 12, 2022
1 parent ab436a8 commit 32472dc
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions SS14.Issues/Services/GithubApiService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public async IAsyncEnumerable<Issue> IterateIssues(long installationId, string r
var from = DateTimeOffset.Now;

Log.Information("Syncing issues for repository: {Repository}", repositorySearchKey);
Log.Debug("Syncing issues from date: {From}", from);
Log.Information("Syncing issues from date: {From}", from);
var stopwatch = new Stopwatch();
stopwatch.Start();
while (true)
Expand All @@ -109,22 +109,20 @@ public async IAsyncEnumerable<Issue> IterateIssues(long installationId, string r
break;

from = issues.Items[^1].CreatedAt;
page = 0;
page = -1;

Log.Debug("Syncing issues from date: {From}", from);

var limit = client.GetLastApiInfo().RateLimit;
if (limit.Remaining == 0)
{
Log.Debug("Hit rate limit. Waiting for: {WaitTime}", limit.Reset - DateTimeOffset.Now);
await Task.Delay(limit.Reset - DateTimeOffset.Now);
}
continue;
Log.Information("Syncing issues from date: {From}", from);
}

page++;
//slow down rate requests are made at
await Task.Delay(10);

var limit = client.GetLastApiInfo().RateLimit;
if (limit.Remaining <= 1)
{
var waitTime = limit.Reset - DateTimeOffset.Now + TimeSpan.FromSeconds(10);
Log.Information("Hit rate limit. Waiting for: {WaitTime}", waitTime);
await Task.Delay(waitTime);
}
}
stopwatch.Stop();
Log.Information("Finished syncing issues. Time taken: {Elapsed}", stopwatch.Elapsed);
Expand Down

0 comments on commit 32472dc

Please sign in to comment.