pub struct TaskMetadata {
pub id: TaskId,
pub name: String,
pub state: TaskState,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
pub max_retries: u32,
pub timeout_secs: Option<u64>,
pub priority: i32,
pub group_id: Option<Uuid>,
pub chord_id: Option<Uuid>,
pub dependencies: HashSet<TaskId>,
}Expand description
Task metadata including execution information
Fields§
§id: TaskIdUnique task identifier
name: StringTask name/type identifier
state: TaskStateCurrent state of the task
created_at: DateTime<Utc>When the task was created
updated_at: DateTime<Utc>When the task was last updated
max_retries: u32Maximum number of retry attempts
timeout_secs: Option<u64>Task timeout in seconds
priority: i32Task priority (higher = more important)
group_id: Option<Uuid>Group ID (for workflow grouping)
chord_id: Option<Uuid>Chord ID (for barrier synchronization)
dependencies: HashSet<TaskId>Task dependencies (tasks that must complete before this task can execute)
Implementations§
Source§impl TaskMetadata
impl TaskMetadata
pub fn new(name: String) -> Self
pub fn with_max_retries(self, max_retries: u32) -> Self
pub fn with_timeout(self, timeout_secs: u64) -> Self
pub fn with_priority(self, priority: i32) -> Self
Sourcepub fn with_group_id(self, group_id: Uuid) -> Self
pub fn with_group_id(self, group_id: Uuid) -> Self
Set the group ID for workflow grouping
Sourcepub fn with_chord_id(self, chord_id: Uuid) -> Self
pub fn with_chord_id(self, chord_id: Uuid) -> Self
Set the chord ID for barrier synchronization
Sourcepub fn is_expired(&self) -> bool
pub fn is_expired(&self) -> bool
Check if the task has expired based on its timeout
Sourcepub fn is_terminal(&self) -> bool
pub fn is_terminal(&self) -> bool
Check if the task is in a terminal state (Succeeded or Failed)
Sourcepub fn validate(&self) -> Result<(), String>
pub fn validate(&self) -> Result<(), String>
Validate the task metadata
Returns an error if any of the metadata fields are invalid:
- Name must not be empty
- Max retries must be reasonable (< 1000)
- Timeout must be at least 1 second if set
- Priority must be in valid range (-2147483648 to 2147483647)
§Errors
Returns an error if validation fails.
Sourcepub fn has_timeout(&self) -> bool
pub fn has_timeout(&self) -> bool
Check if task has a timeout configured
Sourcepub fn has_group_id(&self) -> bool
pub fn has_group_id(&self) -> bool
Check if task is part of a group
Sourcepub fn has_chord_id(&self) -> bool
pub fn has_chord_id(&self) -> bool
Check if task is part of a chord
Sourcepub const fn has_priority(&self) -> bool
pub const fn has_priority(&self) -> bool
Check if task has custom priority (non-zero)
Sourcepub const fn is_high_priority(&self) -> bool
pub const fn is_high_priority(&self) -> bool
Check if task has high priority (priority > 0)
Sourcepub const fn is_low_priority(&self) -> bool
pub const fn is_low_priority(&self) -> bool
Check if task has low priority (priority < 0)
Sourcepub fn with_dependency(self, dependency: TaskId) -> Self
pub fn with_dependency(self, dependency: TaskId) -> Self
Add a task dependency
Sourcepub fn with_dependencies(
self,
dependencies: impl IntoIterator<Item = TaskId>,
) -> Self
pub fn with_dependencies( self, dependencies: impl IntoIterator<Item = TaskId>, ) -> Self
Add multiple task dependencies
Sourcepub fn has_dependencies(&self) -> bool
pub fn has_dependencies(&self) -> bool
Check if task has any dependencies
Sourcepub fn dependency_count(&self) -> usize
pub fn dependency_count(&self) -> usize
Get the number of dependencies
Sourcepub fn depends_on(&self, task_id: &TaskId) -> bool
pub fn depends_on(&self, task_id: &TaskId) -> bool
Check if a specific task is a dependency
Sourcepub fn remove_dependency(&mut self, task_id: &TaskId) -> bool
pub fn remove_dependency(&mut self, task_id: &TaskId) -> bool
Remove a dependency
Sourcepub fn clear_dependencies(&mut self)
pub fn clear_dependencies(&mut self)
Clear all dependencies
Sourcepub fn is_pending(&self) -> bool
pub fn is_pending(&self) -> bool
Check if task is in Pending state
Sourcepub fn is_running(&self) -> bool
pub fn is_running(&self) -> bool
Check if task is in Running state
Sourcepub fn is_succeeded(&self) -> bool
pub fn is_succeeded(&self) -> bool
Check if task is in Succeeded state
Sourcepub fn is_retrying(&self) -> bool
pub fn is_retrying(&self) -> bool
Check if task is in Retrying state
Sourcepub fn is_reserved(&self) -> bool
pub fn is_reserved(&self) -> bool
Check if task is in Reserved state
Sourcepub fn time_remaining(&self) -> Option<Duration>
pub fn time_remaining(&self) -> Option<Duration>
Get remaining time before timeout (None if no timeout or already expired)
§Example
use celers_core::TaskMetadata;
let task = TaskMetadata::new("test".to_string()).with_timeout(60);
if let Some(remaining) = task.time_remaining() {
println!("Task has {} seconds remaining", remaining.num_seconds());
}Sourcepub fn time_elapsed(&self) -> Duration
pub fn time_elapsed(&self) -> Duration
Get the time elapsed since task creation
§Example
use celers_core::TaskMetadata;
let task = TaskMetadata::new("test".to_string());
let elapsed = task.time_elapsed();
assert!(elapsed.num_seconds() >= 0);Sourcepub fn can_retry(&self) -> bool
pub fn can_retry(&self) -> bool
Check if task can be retried based on current retry count
§Example
use celers_core::{TaskMetadata, TaskState};
let mut task = TaskMetadata::new("test".to_string()).with_max_retries(3);
task.state = TaskState::Failed("error".to_string());
assert!(task.can_retry());
task.state = TaskState::Retrying(3);
assert!(!task.can_retry());Sourcepub const fn retry_count(&self) -> u32
pub const fn retry_count(&self) -> u32
Get current retry count
§Example
use celers_core::{TaskMetadata, TaskState};
let mut task = TaskMetadata::new("test".to_string());
task.state = TaskState::Retrying(2);
assert_eq!(task.retry_count(), 2);Sourcepub const fn retries_remaining(&self) -> u32
pub const fn retries_remaining(&self) -> u32
Get remaining retry attempts
§Example
use celers_core::{TaskMetadata, TaskState};
let mut task = TaskMetadata::new("test".to_string()).with_max_retries(5);
task.state = TaskState::Retrying(2);
assert_eq!(task.retries_remaining(), 3);Sourcepub fn is_part_of_workflow(&self) -> bool
pub fn is_part_of_workflow(&self) -> bool
Check if task is part of any workflow (group or chord)
§Example
use celers_core::TaskMetadata;
use uuid::Uuid;
let task = TaskMetadata::new("test".to_string())
.with_group_id(Uuid::new_v4());
assert!(task.is_part_of_workflow());Sourcepub fn get_group_id(&self) -> Option<&Uuid>
pub fn get_group_id(&self) -> Option<&Uuid>
Get group ID if task is part of a group
Sourcepub fn get_chord_id(&self) -> Option<&Uuid>
pub fn get_chord_id(&self) -> Option<&Uuid>
Get chord ID if task is part of a chord
Sourcepub fn mark_as_running(&mut self)
pub fn mark_as_running(&mut self)
Update task state to Running
§Example
use celers_core::{TaskMetadata, TaskState};
let mut task = TaskMetadata::new("test".to_string());
task.mark_as_running();
assert!(task.is_running());Sourcepub fn mark_as_succeeded(&mut self, result: Vec<u8>)
pub fn mark_as_succeeded(&mut self, result: Vec<u8>)
Update task state to Succeeded with result
§Example
use celers_core::{TaskMetadata, TaskState};
let mut task = TaskMetadata::new("test".to_string());
task.mark_as_succeeded(vec![1, 2, 3]);
assert!(task.is_succeeded());Sourcepub fn mark_as_failed(&mut self, error: impl Into<String>)
pub fn mark_as_failed(&mut self, error: impl Into<String>)
Update task state to Failed with error message
§Example
use celers_core::{TaskMetadata, TaskState};
let mut task = TaskMetadata::new("test".to_string());
task.mark_as_failed("Connection timeout");
assert!(task.is_failed());Sourcepub fn with_new_id(&self) -> Self
pub fn with_new_id(&self) -> Self
Clone task with a new ID (useful for task retry/duplication)
§Example
use celers_core::TaskMetadata;
let task = TaskMetadata::new("test".to_string()).with_priority(5);
let cloned = task.with_new_id();
assert_ne!(task.id, cloned.id);
assert_eq!(task.name, cloned.name);
assert_eq!(task.priority, cloned.priority);Trait Implementations§
Source§impl Clone for TaskMetadata
impl Clone for TaskMetadata
Source§fn clone(&self) -> TaskMetadata
fn clone(&self) -> TaskMetadata
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more