redis_queue/manager/
dispatch.rs1use redis::FromRedisValue;
4
5use crate::types::Entry;
6
7use core::future::Future;
8
9#[derive(Debug, PartialEq, Eq, Clone, Copy)]
10pub enum TaskResultKind {
12 Invalid,
14 TempFail,
18 Failure,
20 Success,
22}
23
24pub struct TaskResult<T> {
28 pub data: Entry<T>,
32 pub kind: TaskResultKind,
34}
35
36impl TaskResultKind {
37 pub const fn is_need_retry(&self) -> bool {
39 match self {
40 Self::TempFail => true,
41 _ => false,
42 }
43 }
44}
45
46pub trait Dispatch {
48 type PayloadType: FromRedisValue;
50 type Future: Future<Output = TaskResult<Self::PayloadType>>;
52
53 fn send(&self, data: Entry<Self::PayloadType>) -> Self::Future;
55}
56
57impl<T: Dispatch> Dispatch for std::sync::Arc<T> {
58 type PayloadType = T::PayloadType;
59 type Future = T::Future;
60
61 #[inline(always)]
62 fn send(&self, data: Entry<Self::PayloadType>) -> Self::Future {
63 T::send(self, data)
64 }
65}
66
67impl<T: Dispatch> Dispatch for std::rc::Rc<T> {
68 type PayloadType = T::PayloadType;
69 type Future = T::Future;
70
71 #[inline(always)]
72 fn send(&self, data: Entry<Self::PayloadType>) -> Self::Future {
73 T::send(self, data)
74 }
75}
76
77impl<T: Dispatch> Dispatch for Box<T> {
78 type PayloadType = T::PayloadType;
79 type Future = T::Future;
80
81 #[inline(always)]
82 fn send(&self, data: Entry<Self::PayloadType>) -> Self::Future {
83 T::send(self, data)
84 }
85}