Skip to content

Commit

Permalink
[Http Actions -> FunRun] Add retries for FunRun http actions reques…
Browse files Browse the repository at this point in the history
…ts (#30080)

GitOrigin-RevId: 4313db095b11c3710b9c1c3a1237af93df48c724
  • Loading branch information
jordanhunt22 authored and Convex, Inc. committed Sep 26, 2024
1 parent 7275413 commit 096031c
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions crates/common/src/retriable_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,18 @@ use parking_lot::Mutex;
///
/// This struct does not implement `Clone` but provides a fallible `try_clone`
/// method which will only succeed if the stream has never been polled.
pub struct RetriableStream<T: TryStream> {
pub struct RetriableStream<T: TryStream + std::marker::Unpin>
where
T::Error: FromAnyhowError,
{
shared_inner: Arc<Mutex<Option<T>>>,
inner: Option<T>,
}

impl<T: TryStream> Clone for RetriableStream<T> {
impl<T: TryStream + std::marker::Unpin> Clone for RetriableStream<T>
where
T::Error: FromAnyhowError,
{
fn clone(&self) -> Self {
Self {
shared_inner: self.shared_inner.clone(),
Expand All @@ -35,7 +41,10 @@ impl<T: TryStream> Clone for RetriableStream<T> {
}
}

impl<T: TryStream> RetriableStream<T> {
impl<T: TryStream + std::marker::Unpin> RetriableStream<T>
where
T::Error: FromAnyhowError,
{
pub fn new(body: T) -> Self {
Self {
shared_inner: Arc::new(Mutex::new(Some(body))),
Expand Down Expand Up @@ -92,3 +101,9 @@ impl FromAnyhowError for axum::Error {
Self::new(err)
}
}

impl FromAnyhowError for anyhow::Error {
fn from_anyhow_error(err: anyhow::Error) -> Self {
err
}
}

0 comments on commit 096031c

Please sign in to comment.