Skip to content

Commit 68d77f0

Browse files
committed
Add session schedule configuration fields to configuration type
1 parent ceea9f6 commit 68d77f0

3 files changed

Lines changed: 92 additions & 15 deletions

File tree

Cargo.lock

Lines changed: 2 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/hotfix/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ anyhow = { workspace = true }
2424
aws-config = { version = "1", optional = true }
2525
aws-sdk-dynamodb = { version = "^0.39", optional = true }
2626
async-trait = "^0.1.73"
27+
chrono = { version = "0.4", features = ["serde"] }
2728
futures = "^0.3.28"
2829
hotfix-message = { version = "0.0.23", path = "../hotfix-message" }
2930
mongodb = { version = "^2.7", optional = true }
@@ -36,8 +37,6 @@ serde_dynamo = { version = "^4.2.12", features = ["aws-sdk-dynamodb+0_39"], opti
3637
thiserror = { workspace = true }
3738
tokio = { version = "^1", features = ["full"] }
3839
tokio-rustls = "^0.24.1"
39-
tokio-stream = "^0.1.14"
4040
toml = { workspace = true }
4141
tracing = { workspace = true }
42-
log = "0.4.20"
4342
uuid = { version = "1.5.0", features = ["v4"] }

crates/hotfix/src/config.rs

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
//! config file. See the
66
//! [example project's config file](https://github.com/Validus-Risk-Management/hotfix/blob/main/examples/simple-new-order/config/test-config.toml)
77
//! for more detail.
8+
use chrono::{NaiveTime, Weekday};
89
use serde::Deserialize;
910
use std::fs;
1011
use std::path::Path;
@@ -30,6 +31,17 @@ pub struct TlsConfig {
3031
pub ca_certificate_path: String,
3132
}
3233

34+
/// Session schedule configuration
35+
#[derive(Clone, Debug, Deserialize, PartialEq)]
36+
pub struct ScheduleConfig {
37+
pub start_time: Option<NaiveTime>,
38+
pub end_time: Option<NaiveTime>,
39+
pub start_day: Option<Weekday>,
40+
pub end_day: Option<Weekday>,
41+
#[serde(default)]
42+
pub weekdays: Vec<Weekday>,
43+
}
44+
3345
fn default_reconnect_interval() -> u64 {
3446
30
3547
}
@@ -61,12 +73,16 @@ pub struct SessionConfig {
6173
/// The interval we should attempt to reconnect at in seconds.
6274
pub reconnect_interval: u64,
6375
/// Specifies whether we should reset the state of the message store on logon.
76+
#[serde(default)]
6477
pub reset_on_logon: bool,
78+
/// The schedule configuration for the session
79+
pub schedule: Option<ScheduleConfig>,
6580
}
6681

6782
#[cfg(test)]
6883
mod tests {
6984
use crate::config::{Config, TlsConfig};
85+
use chrono::{NaiveTime, Weekday};
7086

7187
#[test]
7288
fn test_simple_config() {
@@ -104,4 +120,77 @@ reset_on_logon = false
104120
assert_eq!(session_config.tls_config, Some(expected_tls_config));
105121
assert_eq!(session_config.reconnect_interval, 30);
106122
}
123+
124+
#[test]
125+
fn test_schedule_config_weekdays() {
126+
let config_contents = r#"
127+
[[sessions]]
128+
begin_string = "FIX.4.4"
129+
sender_comp_id = "send-comp-id"
130+
target_comp_id = "target-comp-id"
131+
heartbeat_interval = 30
132+
133+
connection_port = 443
134+
connection_host = "127.0.0.1"
135+
136+
[sessions.schedule]
137+
start_time = "00:00:00"
138+
end_time = "23:55:00"
139+
weekdays = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"]
140+
"#;
141+
142+
let config: Config = toml::from_str(config_contents).unwrap();
143+
assert_eq!(config.sessions.len(), 1);
144+
let session = config.sessions.first().unwrap();
145+
146+
assert_eq!(session.schedule.is_some(), true);
147+
let schedule = session.schedule.as_ref().unwrap();
148+
149+
assert_eq!(schedule.start_time, NaiveTime::from_hms_opt(0, 0, 0));
150+
assert_eq!(schedule.end_time, NaiveTime::from_hms_opt(23, 55, 0));
151+
assert_eq!(
152+
schedule.weekdays,
153+
vec![
154+
Weekday::Mon,
155+
Weekday::Tue,
156+
Weekday::Wed,
157+
Weekday::Thu,
158+
Weekday::Fri
159+
]
160+
);
161+
assert_eq!(schedule.start_day, None);
162+
assert_eq!(schedule.end_day, None);
163+
}
164+
165+
#[test]
166+
fn test_schedule_config_weeklong_session() {
167+
let config_contents = r#"
168+
[[sessions]]
169+
begin_string = "FIX.4.4"
170+
sender_comp_id = "send-comp-id"
171+
target_comp_id = "target-comp-id"
172+
heartbeat_interval = 30
173+
174+
connection_port = 443
175+
connection_host = "127.0.0.1"
176+
177+
[sessions.schedule]
178+
start_time = "00:00:00"
179+
end_time = "23:55:00"
180+
start_day = "Monday"
181+
end_day = "Friday"
182+
"#;
183+
184+
let config: Config = toml::from_str(config_contents).unwrap();
185+
assert_eq!(config.sessions.len(), 1);
186+
let session = config.sessions.first().unwrap();
187+
188+
assert_eq!(session.schedule.is_some(), true);
189+
let schedule = session.schedule.as_ref().unwrap();
190+
191+
assert_eq!(schedule.start_time, NaiveTime::from_hms_opt(0, 0, 0));
192+
assert_eq!(schedule.end_time, NaiveTime::from_hms_opt(23, 55, 0));
193+
assert_eq!(schedule.start_day, Some(Weekday::Mon));
194+
assert_eq!(schedule.end_day, Some(Weekday::Fri));
195+
}
107196
}

0 commit comments

Comments
 (0)