reinhardt-tasks 0.3.2

Background task execution and scheduling
Documentation
//! Task queue management

#![allow(deprecated)] // QueueConfig is deprecated; this module still defines and re-exports it during the compatibility window.

use crate::backend::TaskExecutionError;
use crate::{Task, TaskBackend, TaskId};

/// Configuration for a task queue.
#[deprecated(
	since = "0.2.0",
	note = "Use `QueueSettings` with the `#[settings]` macro instead."
)]
#[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
	}

	/// 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()
	}
}