Skip to main content

reinhardt_tasks/
queue.rs

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