Skip to main content

reinhardt_tasks/
queue.rs

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