Skip to content

Commit

Permalink
fix: propagate error if issue with polling
Browse files Browse the repository at this point in the history
  • Loading branch information
dubadub committed Jan 15, 2025
1 parent 3d59270 commit 62c6af3
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cooklang-sync-client"
version = "0.2.4"
version = "0.2.5"
authors = ["Alexey Dubovskoy <alexey@cooklang.org>"]
edition = "2021"
description = "A client library for cooklang-sync"
Expand Down
5 changes: 2 additions & 3 deletions client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,9 @@ pub fn run(
#[uniffi::export]
pub fn wait_remote_update(
api_endpoint: &str,
remote_token: &str,
wait_time: u64,
remote_token: &str
) -> Result<(), errors::SyncError> {
Runtime::new()?.block_on(remote::Remote::new(api_endpoint, remote_token).poll(wait_time))?;
Runtime::new()?.block_on(remote::Remote::new(api_endpoint, remote_token).poll())?;

Ok(())
}
Expand Down
8 changes: 5 additions & 3 deletions client/src/remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,12 @@ impl Remote {
}
}

pub async fn poll(&self, seconds: u64) -> Result<()> {
pub async fn poll(&self) -> Result<()> {
trace!("started poll");

// setting its larger than the request timeout to avoid timeouts from the server
let seconds = REQUEST_TIMEOUT_SECS + 10;

let seconds_string = seconds.to_string();

let response = self
Expand All @@ -205,8 +208,7 @@ impl Remote {
Ok(response) => match response.status() {
StatusCode::OK => Ok(()),
StatusCode::UNAUTHORIZED => Err(SyncError::Unauthorized),
// Don't need to error as it's expected to be cancelled from time to time
_ => Ok(()),
_ => Err(SyncError::Unknown),
},
Err(e) if e.is_timeout() => Ok(()), // Ignore timeout errors
Err(e) => Err(e.into()),
Expand Down
4 changes: 2 additions & 2 deletions client/src/syncer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::connection::{get_connection, ConnectionPool};
use crate::errors::SyncError;
use crate::models;
use crate::registry;
use crate::remote::{CommitResultStatus, Remote, REQUEST_TIMEOUT_SECS};
use crate::remote::{CommitResultStatus, Remote};

type Result<T, E = SyncError> = std::result::Result<T, E>;

Expand Down Expand Up @@ -86,7 +86,7 @@ async fn download_loop(

// need to be longer than request timeout to make sure we don't get
// client side timeout error
remote.poll(REQUEST_TIMEOUT_SECS + 10).await?;
remote.poll().await?;
}
}

Expand Down

0 comments on commit 62c6af3

Please sign in to comment.