Skip to content

Commit e5e4c92

Browse files
committed
Disable GitHub retry on the server.
This disables the GitHub rate limit retry logic on the server. Generally for webhooks, the server must respond within 10 seconds. If it ever hits the rate limit, it will likely sleep for several minutes, meaning it will be guaranteed to be killed. Whether or not retries are enabled is now a property of `GithubClient`. It is enabled for the CLI prioritization tool (which added this retry logic in the first place in #579).
1 parent 46af494 commit e5e4c92

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/actions.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ pub fn to_human(d: DateTime<Utc>) -> String {
108108
#[async_trait]
109109
impl<'a> Action for Step<'a> {
110110
async fn call(&self) -> anyhow::Result<String> {
111-
let gh = GithubClient::new_from_env();
111+
let mut gh = GithubClient::new_from_env();
112+
gh.set_retry_rate_limit(true);
112113

113114
let mut context = Context::new();
114115
let mut results = HashMap::new();

src/github.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ impl GithubClient {
3131
.with_context(|| format!("building reqwest {}", req_dbg))?;
3232

3333
let mut resp = self.client.execute(req.try_clone().unwrap()).await?;
34-
if let Some(sleep) = Self::needs_retry(&resp).await {
35-
resp = self.retry(req, sleep, MAX_ATTEMPTS).await?;
34+
if self.retry_rate_limit {
35+
if let Some(sleep) = Self::needs_retry(&resp).await {
36+
resp = self.retry(req, sleep, MAX_ATTEMPTS).await?;
37+
}
3638
}
3739
let maybe_err = resp.error_for_status_ref().err();
3840
let body = resp
@@ -2146,6 +2148,8 @@ pub struct GithubClient {
21462148
api_url: String,
21472149
graphql_url: String,
21482150
raw_url: String,
2151+
/// If `true`, requests will sleep if it hits GitHub's rate limit.
2152+
retry_rate_limit: bool,
21492153
}
21502154

21512155
impl GithubClient {
@@ -2156,6 +2160,7 @@ impl GithubClient {
21562160
api_url,
21572161
graphql_url,
21582162
raw_url,
2163+
retry_rate_limit: false,
21592164
}
21602165
}
21612166

@@ -2171,6 +2176,14 @@ impl GithubClient {
21712176
)
21722177
}
21732178

2179+
/// Sets whether or not this client will retry when it hits GitHub's rate limit.
2180+
///
2181+
/// Just beware that the retry may take a long time (like 30 minutes,
2182+
/// depending on various factors).
2183+
pub fn set_retry_rate_limit(&mut self, retry: bool) {
2184+
self.retry_rate_limit = retry;
2185+
}
2186+
21742187
pub fn raw(&self) -> &Client {
21752188
&self.client
21762189
}

0 commit comments

Comments
 (0)