Skip to content

Commit 1c6f2e4

Browse files
Merge pull request #168 from code0-tech/#167-aquila-grpc-channel-timeout
made timeout configurable
2 parents b2e06e5 + 4b180f3 commit 1c6f2e4

2 files changed

Lines changed: 17 additions & 5 deletions

File tree

src/flow_service/mod.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::{
22
flow_definition::Reader,
33
flow_service::{auth::get_authorization_metadata, retry::create_channel_with_retry},
44
};
5+
use tokio::time::Duration;
56
use tonic::{Extensions, Request, transport::Channel};
67
use tucana::{
78
aquila::{ModuleUpdateRequest, module_service_client::ModuleServiceClient},
@@ -28,7 +29,13 @@ impl FlowUpdateService {
2829
///
2930
/// This reads the definition files from the given path as modules and initializes the
3031
/// service with those module definitions.
31-
pub async fn from_url(aquila_url: String, definition_path: &str, aquila_token: String) -> Self {
32+
pub async fn from_url(
33+
aquila_url: String,
34+
definition_path: &str,
35+
aquila_token: String,
36+
connect_timeout: Duration,
37+
request_timeout: Duration,
38+
) -> Self {
3239
let reader = Reader::configure(definition_path.to_string(), true, vec![], None);
3340
let modules = match reader.read_modules() {
3441
Ok(modules) => modules,
@@ -38,7 +45,8 @@ impl FlowUpdateService {
3845
}
3946
};
4047

41-
let channel = create_channel_with_retry("Aquila", aquila_url).await;
48+
let channel =
49+
create_channel_with_retry("Aquila", aquila_url, connect_timeout, request_timeout).await;
4250

4351
Self {
4452
modules,

src/flow_service/retry.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,20 @@ const MAX_BACKOFF: u64 = 2000 * 60;
55
const MAX_RETRIES: i8 = 10;
66

77
// Will create a channel and retry if its not possible
8-
pub async fn create_channel_with_retry(channel_name: &str, url: String) -> Channel {
8+
pub async fn create_channel_with_retry(
9+
channel_name: &str,
10+
url: String,
11+
connect_timeout: Duration,
12+
request_timeout: Duration,
13+
) -> Channel {
914
let mut backoff = 100;
1015
let mut retries = 0;
1116

1217
loop {
1318
let channel = match Endpoint::from_shared(url.clone()) {
1419
Ok(c) => {
1520
log::debug!("Creating a new endpoint for the: {} Service", channel_name);
16-
c.connect_timeout(Duration::from_secs(2))
17-
.timeout(Duration::from_secs(10))
21+
c.connect_timeout(connect_timeout).timeout(request_timeout)
1822
}
1923
Err(err) => {
2024
panic!(

0 commit comments

Comments
 (0)