finga
1100ba1b13
Add support for timeout and deadline parameters when messages are sent to a message queue. To keep code duplication small, the `utils.rs` file contains a helper function to parse the `Duration` from the `String` received from the timeout parameter. Add conflict rules for the timeout and deadline parameters.
17 lines
468 B
Rust
17 lines
468 B
Rust
use anyhow::Result;
|
|
use std::{str, time::Duration};
|
|
|
|
pub fn parse_duration(timeout: &str) -> Result<Duration> {
|
|
if timeout.ends_with("ms") {
|
|
Ok(Duration::from_millis(
|
|
timeout[0..timeout.len() - 2].parse::<u64>()?,
|
|
))
|
|
} else if timeout.ends_with("s") {
|
|
Ok(Duration::from_secs(
|
|
timeout[0..timeout.len() - 1].parse::<u64>()?,
|
|
))
|
|
} else {
|
|
Ok(Duration::from_secs(timeout.parse::<u64>()?))
|
|
}
|
|
}
|