Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: NixOS/hydra
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 1c44de1779d0
Choose a base ref
...
head repository: NixOS/hydra
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: f9870b5fce85
Choose a head ref
  • 2 commits
  • 1 file changed
  • 2 contributors

Commits on Nov 9, 2018

  1. Verified

    This commit was signed with the committer’s verified signature.
    Mic92 Jörg Thalheim
    Copy the full SHA
    7916c6b View commit details

Commits on Nov 12, 2018

  1. Merge pull request #612 from input-output-hk/devops-1126

    [DEVOPS-1126] throttle github status calls to remain under api ratelimits
    edolstra authored Nov 12, 2018
    Copy the full SHA
    f9870b5 View commit details
Showing with 16 additions and 0 deletions.
  1. +16 −0 src/lib/Hydra/Plugin/GithubStatus.pm
16 changes: 16 additions & 0 deletions src/lib/Hydra/Plugin/GithubStatus.pm
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@ use HTTP::Request;
use JSON;
use LWP::UserAgent;
use Hydra::Helper::CatalystUtils;
use List::Util qw(max);

sub toGithubState {
my ($buildStatus) = @_;
@@ -65,6 +66,21 @@ sub common {
$req->content($body);
my $res = $ua->request($req);
print STDERR $res->status_line, ": ", $res->decoded_content, "\n" unless $res->is_success;
my $limit = $res->header("X-RateLimit-Limit");
my $limitRemaining = $res->header("X-RateLimit-Remaining");
my $limitReset = $res->header("X-RateLimit-Reset");
my $now = time();
my $diff = $limitReset - $now;
my $delay = (($limit - $limitRemaining) / $diff) * 5;
if ($limitRemaining < 1000) {
$delay = max(1, $delay);
}
if ($limitRemaining < 2000) {
print STDERR "GithubStatus ratelimit $limitRemaining/$limit, resets in $diff, sleeping $delay\n";
sleep $delay;
} else {
print STDERR "GithubStatus ratelimit $limitRemaining/$limit, resets in $diff\n";
}
}
}
}