1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//! Task queue management
use crate::backend::TaskExecutionError;
use crate::{Task, TaskBackend, TaskId};
/// Configuration for a task queue.
#[derive(Debug, Clone)]
pub struct QueueConfig {
/// Name of the queue.
pub name: String,
/// Maximum number of retry attempts for failed tasks.
pub max_retries: u32,
}
impl QueueConfig {
/// Creates a new queue configuration with the given name and default retry count.
pub fn new(name: String) -> Self {
Self {
name,
max_retries: 3,
}
}
}
impl Default for QueueConfig {
fn default() -> Self {
Self::new("default".to_string())
}
}
/// A task queue that delegates to a backend for task storage and retrieval.
pub struct TaskQueue;
impl TaskQueue {
/// Creates a new task queue with default configuration.
pub fn new() -> Self {
Self
}
/// Creates a new task queue with the given configuration.
pub fn with_config(_config: QueueConfig) -> Self {
Self
}
/// Enqueues a task for execution through the specified backend.
pub async fn enqueue(
&self,
task: Box<dyn Task>,
backend: &dyn TaskBackend,
) -> Result<TaskId, TaskExecutionError> {
backend.enqueue(task).await
}
}
impl Default for TaskQueue {
fn default() -> Self {
Self::new()
}
}