use crate::key::{RequestId, ShardKey};
use grommet_core::ClassId;
use std::time::Duration;
pub trait Work: Send + 'static {
type Key: ShardKey;
type Id: RequestId;
fn key(&self) -> Self::Key;
fn request_id(&self) -> Option<Self::Id> {
None
}
fn class(&self) -> ClassId;
fn time_to_live(&self) -> Option<Duration> {
None
}
}
pub struct Envelope<W: Work> {
pub(crate) key: W::Key,
pub(crate) class: ClassId,
pub(crate) request_id: Option<W::Id>,
pub(crate) expires_at: Option<Duration>,
pub(crate) enqueued: Duration,
pub(crate) work: W,
}
impl<W: Work> Envelope<W> {
pub fn key(&self) -> W::Key {
self.key
}
pub fn class(&self) -> ClassId {
self.class
}
pub fn work(&self) -> &W {
&self.work
}
pub fn into_work(self) -> W {
self.work
}
}
pub(crate) struct Stamped<W: Work> {
pub(crate) enqueued: Duration,
pub(crate) request_id: Option<W::Id>,
pub(crate) work: W,
}