refactor(deps): replace tokio Mutex/join!, add NetworkErrorKind enum, remove reqwest from error types
This commit is contained in:
@@ -5,8 +5,8 @@ use reqwest::header::{ACCEPT, HeaderMap, HeaderValue};
|
||||
use reqwest::{Client, Response, StatusCode};
|
||||
use std::pin::Pin;
|
||||
use std::sync::Arc;
|
||||
use std::sync::Mutex;
|
||||
use std::time::{Duration, Instant};
|
||||
use tokio::sync::Mutex;
|
||||
use tokio::time::sleep;
|
||||
use tracing::{debug, warn};
|
||||
|
||||
@@ -131,7 +131,16 @@ impl GitLabClient {
|
||||
let mut last_response = None;
|
||||
|
||||
for attempt in 0..=Self::MAX_RETRIES {
|
||||
let delay = self.rate_limiter.lock().await.check_delay();
|
||||
// SAFETY: std::sync::Mutex blocks the executor thread while held. This is safe
|
||||
// because the critical section is a single Instant::now() comparison with no I/O.
|
||||
// If async work is ever added inside the lock, switch to an async-aware lock.
|
||||
let delay = {
|
||||
let mut limiter = self
|
||||
.rate_limiter
|
||||
.lock()
|
||||
.unwrap_or_else(|poisoned| poisoned.into_inner());
|
||||
limiter.check_delay()
|
||||
};
|
||||
if let Some(d) = delay {
|
||||
sleep(d).await;
|
||||
}
|
||||
@@ -146,7 +155,8 @@ impl GitLabClient {
|
||||
.await
|
||||
.map_err(|e| LoreError::GitLabNetworkError {
|
||||
base_url: self.base_url.clone(),
|
||||
source: Some(e),
|
||||
kind: crate::core::error::NetworkErrorKind::Other,
|
||||
detail: Some(format!("{e:?}")),
|
||||
})?;
|
||||
|
||||
if response.status() == StatusCode::TOO_MANY_REQUESTS && attempt < Self::MAX_RETRIES {
|
||||
@@ -197,7 +207,14 @@ impl GitLabClient {
|
||||
}
|
||||
|
||||
status if status.is_success() => {
|
||||
let text = response.text().await?;
|
||||
let text = response
|
||||
.text()
|
||||
.await
|
||||
.map_err(|e| LoreError::GitLabNetworkError {
|
||||
base_url: self.base_url.clone(),
|
||||
kind: crate::core::error::NetworkErrorKind::Other,
|
||||
detail: Some(format!("{e:?}")),
|
||||
})?;
|
||||
serde_json::from_str(&text).map_err(|e| {
|
||||
let preview = if text.len() > 500 {
|
||||
&text[..text.floor_char_boundary(500)]
|
||||
@@ -516,7 +533,16 @@ impl GitLabClient {
|
||||
let mut last_response = None;
|
||||
|
||||
for attempt in 0..=Self::MAX_RETRIES {
|
||||
let delay = self.rate_limiter.lock().await.check_delay();
|
||||
// SAFETY: std::sync::Mutex blocks the executor thread while held. This is safe
|
||||
// because the critical section is a single Instant::now() comparison with no I/O.
|
||||
// If async work is ever added inside the lock, switch to an async-aware lock.
|
||||
let delay = {
|
||||
let mut limiter = self
|
||||
.rate_limiter
|
||||
.lock()
|
||||
.unwrap_or_else(|poisoned| poisoned.into_inner());
|
||||
limiter.check_delay()
|
||||
};
|
||||
if let Some(d) = delay {
|
||||
sleep(d).await;
|
||||
}
|
||||
@@ -532,7 +558,8 @@ impl GitLabClient {
|
||||
.await
|
||||
.map_err(|e| LoreError::GitLabNetworkError {
|
||||
base_url: self.base_url.clone(),
|
||||
source: Some(e),
|
||||
kind: crate::core::error::NetworkErrorKind::Other,
|
||||
detail: Some(format!("{e:?}")),
|
||||
})?;
|
||||
|
||||
if response.status() == StatusCode::TOO_MANY_REQUESTS && attempt < Self::MAX_RETRIES {
|
||||
@@ -726,14 +753,14 @@ impl GitLabClient {
|
||||
)> {
|
||||
let (state_res, label_res, milestone_res) = match entity_type {
|
||||
"issue" => {
|
||||
tokio::join!(
|
||||
futures::join!(
|
||||
self.fetch_issue_state_events(gitlab_project_id, iid),
|
||||
self.fetch_issue_label_events(gitlab_project_id, iid),
|
||||
self.fetch_issue_milestone_events(gitlab_project_id, iid),
|
||||
)
|
||||
}
|
||||
"merge_request" => {
|
||||
tokio::join!(
|
||||
futures::join!(
|
||||
self.fetch_mr_state_events(gitlab_project_id, iid),
|
||||
self.fetch_mr_label_events(gitlab_project_id, iid),
|
||||
self.fetch_mr_milestone_events(gitlab_project_id, iid),
|
||||
|
||||
Reference in New Issue
Block a user