Fallback to the previous poll interval duration if no poll interval is specified.
This commit is contained in:
parent
df00268d35
commit
f36546a470
@ -12,6 +12,7 @@ pub struct GithubEndpointWatcher {
|
||||
next_poll_allowed: u64,
|
||||
ratelimit_remaining: Option<u64>,
|
||||
ratelimit_reset: Option<u64>,
|
||||
previous_poll_interval: Option<u64>,
|
||||
}
|
||||
|
||||
impl GithubEndpointWatcher {
|
||||
@ -31,6 +32,7 @@ impl GithubEndpointWatcher {
|
||||
next_poll_allowed: 0,
|
||||
ratelimit_remaining: None,
|
||||
ratelimit_reset: None,
|
||||
previous_poll_interval: None,
|
||||
})
|
||||
}
|
||||
|
||||
@ -65,6 +67,9 @@ impl GithubEndpointWatcher {
|
||||
let headers = response.headers();
|
||||
let etag = headers.get(reqwest::header::ETAG).map(|x| x.to_owned());
|
||||
let poll_interval = number_header(headers.get("x-poll-interval"))?;
|
||||
if let Some(interval) = poll_interval {
|
||||
self.previous_poll_interval = Some(interval);
|
||||
}
|
||||
// let ratelimit_limit = headers.get("x-ratelimit-limit").map(|x| x.to_owned());
|
||||
self.ratelimit_remaining = number_header(headers.get("x-ratelimit-remaining"))?;
|
||||
self.ratelimit_reset = number_header(headers.get("x-ratelimit-reset"))?;
|
||||
@ -78,18 +83,27 @@ impl GithubEndpointWatcher {
|
||||
self.etag = etag;
|
||||
self.last_modified_at = last_modified_at;
|
||||
let poll_interval_parsed: u64 = poll_interval.unwrap_or_else(|| {
|
||||
info!("No poll interval returned, defaulting to 5 minute polling.");
|
||||
300
|
||||
let fallback_interval = self.previous_poll_interval.unwrap_or(300);
|
||||
info!(
|
||||
"No poll interval returned, defaulting to {} second polling.",
|
||||
fallback_interval
|
||||
);
|
||||
fallback_interval
|
||||
});
|
||||
self.next_poll_allowed = request_started_at + poll_interval_parsed;
|
||||
return Ok(None);
|
||||
} else {
|
||||
let body = response.json::<serde_json::Value>().await?;
|
||||
|
||||
self.etag = etag;
|
||||
self.last_modified_at = last_modified_at;
|
||||
let poll_interval_parsed: u64 = poll_interval.unwrap_or_else(|| {
|
||||
info!("No poll interval returned, defaulting to 5 minute polling.");
|
||||
300
|
||||
let fallback_interval = self.previous_poll_interval.unwrap_or(300);
|
||||
info!(
|
||||
"No poll interval returned, defaulting to {} second polling.",
|
||||
fallback_interval
|
||||
);
|
||||
fallback_interval
|
||||
});
|
||||
self.next_poll_allowed = request_started_at + poll_interval_parsed;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user