#![allow(dead_code)]
use std::time::Duration;
use serde::{Deserialize, Serialize};
use crate::{
job::Job,
queue::{QueueConfig, QueueSet},
retry::{Backoff, RetryPolicy},
};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub(crate) enum TestQueues {
Alpha,
Beta,
Gamma,
}
impl TestQueues {
pub(crate) const ALPHA_DELAY: Duration = Duration::from_secs(1);
}
impl QueueSet for TestQueues {
fn all() -> &'static [Self] {
&[TestQueues::Alpha, TestQueues::Beta, TestQueues::Gamma]
}
fn name(&self) -> &'static str {
match self {
TestQueues::Alpha => "test.alpha",
TestQueues::Beta => "test.beta",
TestQueues::Gamma => "test.gamma",
}
}
fn config(&self) -> QueueConfig {
match self {
TestQueues::Alpha => QueueConfig::new("test.alpha")
.prefetch(4)
.retry(RetryPolicy::new(3, Backoff::Fixed(Self::ALPHA_DELAY))),
TestQueues::Beta => QueueConfig::new("test.beta")
.prefetch(2)
.retry(RetryPolicy::none()),
TestQueues::Gamma => QueueConfig::new("test.gamma")
.prefetch(1)
.retry(RetryPolicy::none())
.max_priority(0),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub(crate) struct Greet {
pub(crate) name: String,
}
impl Greet {
pub(crate) fn new(name: &str) -> Self {
Self {
name: name.to_owned(),
}
}
}
impl Job for Greet {
type Queue = TestQueues;
const NAME: &'static str = "test::Greet";
const QUEUE: Self::Queue = TestQueues::Alpha;
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub(crate) struct Ping {
pub(crate) seq: u32,
}
impl Job for Ping {
type Queue = TestQueues;
const NAME: &'static str = "test::Ping";
const QUEUE: Self::Queue = TestQueues::Beta;
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub(crate) struct Stubborn {
pub(crate) id: u32,
}
impl Job for Stubborn {
type Queue = TestQueues;
const NAME: &'static str = "test::Stubborn";
const QUEUE: Self::Queue = TestQueues::Beta;
fn retry_policy() -> Option<RetryPolicy> {
Some(RetryPolicy::fixed(2, Duration::from_secs(5)))
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub(crate) struct Nudge {
pub(crate) id: u32,
}
impl Job for Nudge {
type Queue = TestQueues;
const NAME: &'static str = "test::Nudge";
const QUEUE: Self::Queue = TestQueues::Gamma;
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub(crate) struct Orphan {
pub(crate) id: u32,
}
impl Job for Orphan {
type Queue = TestQueues;
const NAME: &'static str = "test::Orphan";
const QUEUE: Self::Queue = TestQueues::Alpha;
}