use crate::protocol::MessageContentType;
#[derive(Copy, Clone, Default)]
pub struct TaskOptions {
pub time_limit: Option<u32>,
pub hard_time_limit: Option<u32>,
pub max_retries: Option<u32>,
pub min_retry_delay: Option<u32>,
pub max_retry_delay: Option<u32>,
pub retry_for_unexpected: Option<bool>,
pub acks_late: Option<bool>,
pub content_type: Option<MessageContentType>,
}
impl TaskOptions {
pub(crate) fn update(&mut self, other: &TaskOptions) {
self.time_limit = self.time_limit.or(other.time_limit);
self.hard_time_limit = self.hard_time_limit.or(other.hard_time_limit);
self.max_retries = self.max_retries.or(other.max_retries);
self.min_retry_delay = self.min_retry_delay.or(other.min_retry_delay);
self.max_retry_delay = self.max_retry_delay.or(other.max_retry_delay);
self.retry_for_unexpected = self.retry_for_unexpected.or(other.retry_for_unexpected);
self.acks_late = self.acks_late.or(other.acks_late);
self.content_type = self.content_type.or(other.content_type);
}
pub(crate) fn override_other(&self, other: &mut TaskOptions) {
other.update(self);
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_update() {
let mut options = TaskOptions {
max_retries: Some(3),
acks_late: Some(true),
..Default::default()
};
let other = TaskOptions {
time_limit: Some(2),
acks_late: Some(false),
..Default::default()
};
options.update(&other);
assert_eq!(options.time_limit, Some(2));
assert_eq!(options.max_retries, Some(3));
assert_eq!(options.acks_late, Some(true));
}
}