use super::{Task, TaskOptions};
use crate::protocol::MessageContentType;
use chrono::{DateTime, Utc};
#[derive(Clone)]
pub struct Signature<T>
where
T: Task,
{
pub(crate) params: T::Params,
pub(crate) queue: Option<String>,
pub(crate) countdown: Option<u32>,
pub(crate) eta: Option<DateTime<Utc>>,
pub(crate) expires_in: Option<u32>,
pub(crate) expires: Option<DateTime<Utc>>,
pub(crate) options: TaskOptions,
}
impl<T> Signature<T>
where
T: Task,
{
pub fn new(params: T::Params) -> Self {
Self {
params,
queue: None,
countdown: None,
eta: None,
expires_in: None,
expires: None,
options: T::DEFAULTS,
}
}
pub fn task_name() -> &'static str {
T::NAME
}
pub fn with_queue(mut self, queue: &str) -> Self {
self.queue = Some(queue.into());
self
}
pub fn with_countdown(mut self, countdown: u32) -> Self {
self.countdown = Some(countdown);
self
}
pub fn with_eta(mut self, eta: DateTime<Utc>) -> Self {
self.eta = Some(eta);
self
}
pub fn with_expires_in(mut self, expires_in: u32) -> Self {
self.expires_in = Some(expires_in);
self
}
pub fn with_expires(mut self, expires: DateTime<Utc>) -> Self {
self.expires = Some(expires);
self
}
pub fn with_content_type(mut self, content_type: MessageContentType) -> Self {
self.options.content_type = Some(content_type);
self
}
pub fn with_time_limit(mut self, time_limit: u32) -> Self {
self.options.time_limit = Some(time_limit);
self
}
pub fn with_hard_time_limit(mut self, time_limit: u32) -> Self {
self.options.hard_time_limit = Some(time_limit);
self
}
}