Skip to content

Commit

Permalink
osrdyne: make extra_lifetime configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
ElysaSrc committed Jul 17, 2024
1 parent 61dacbb commit e9f3ac9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
2 changes: 2 additions & 0 deletions osrdyne/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub struct OsrdyneConfig {
pub max_length: Option<usize>,
pub max_length_bytes: Option<usize>,
pub api_address: String,
pub extra_lifetime: Option<Duration>,
}

impl Default for OsrdyneConfig {
Expand All @@ -43,6 +44,7 @@ impl Default for OsrdyneConfig {
max_length: None,
max_length_bytes: None,
api_address: "0.0.0.0:4242".into(), // TODO: decide on the port
extra_lifetime: None,
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions osrdyne/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use log::error;
use log::info;
use std::collections::BTreeMap;
use std::sync::Arc;
use std::time::Duration;
use tokio::select;
use tokio::signal;
use tokio::spawn;
Expand Down Expand Up @@ -65,6 +66,7 @@ async fn main() -> Result<(), anyhow::Error> {
let pool = Arc::new(Pool::new(
config.pool_id.clone(),
request_queues_policy(&config),
config.extra_lifetime.unwrap_or(Duration::from_secs(1)),
));

// fetch the list of queues from the web API
Expand Down
15 changes: 11 additions & 4 deletions osrdyne/src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,18 @@ pub struct Pool {
pub activity_queue: String,
pub poison_queue: String,

pub extra_lifetime: Duration,

pool_req_prefix: String,
request_queue_policy: BTreeMap<String, ArgumentValue>,
}

impl Pool {
pub fn new(raw_pool_id: String, request_queue_policy: BTreeMap<String, ArgumentValue>) -> Self {
pub fn new(
raw_pool_id: String,
request_queue_policy: BTreeMap<String, ArgumentValue>,
extra_lifetime: Duration,
) -> Self {
let pool_id = utf8_percent_encode(&raw_pool_id, NON_ALPHANUMERIC).to_string();

let request_xchg = format!("{pool_id}-req-xchg");
Expand Down Expand Up @@ -73,6 +79,8 @@ impl Pool {
activity_queue,
poison_queue,

extra_lifetime,

pool_req_prefix,
request_queue_policy,
}
Expand Down Expand Up @@ -280,20 +288,19 @@ impl Pool {
let activity_channel = conn.create_channel().await?;
let orphan_channel = conn.create_channel().await?;
let deadletter_channel = conn.create_channel().await?;
let extra_lifetime = Duration::from_secs(1); // FIXME: make this configurable

tasks.spawn(activity_processor(
self.clone(),
activity_channel,
tracker_client.clone(),
extra_lifetime,
self.extra_lifetime,
));
tasks.spawn(orphan_processor(
self.clone(),
orphan_channel,
tracker_client.clone(),
queue_status,
extra_lifetime,
self.extra_lifetime,
));
tasks.spawn(deadletter_responder(self.clone(), deadletter_channel));

Expand Down

0 comments on commit e9f3ac9

Please sign in to comment.