TaskMetadata

Struct TaskMetadata 

Source
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: TaskId

Unique task identifier

§name: String

Task name/type identifier

§state: TaskState

Current 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: u32

Maximum number of retry attempts

§timeout_secs: Option<u64>

Task timeout in seconds

§priority: i32

Task 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

Source

pub fn new(name: String) -> Self

Source

pub fn with_max_retries(self, max_retries: u32) -> Self

Source

pub fn with_timeout(self, timeout_secs: u64) -> Self

Source

pub fn with_priority(self, priority: i32) -> Self

Source

pub fn with_group_id(self, group_id: Uuid) -> Self

Set the group ID for workflow grouping

Source

pub fn with_chord_id(self, chord_id: Uuid) -> Self

Set the chord ID for barrier synchronization

Source

pub fn age(&self) -> Duration

Get the age of the task (time since creation)

Source

pub fn is_expired(&self) -> bool

Check if the task has expired based on its timeout

Source

pub fn is_terminal(&self) -> bool

Check if the task is in a terminal state (Succeeded or Failed)

Source

pub fn is_active(&self) -> bool

Check if the task is in a running or active state

Source

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.

Source

pub fn has_timeout(&self) -> bool

Check if task has a timeout configured

Source

pub fn has_group_id(&self) -> bool

Check if task is part of a group

Source

pub fn has_chord_id(&self) -> bool

Check if task is part of a chord

Source

pub const fn has_priority(&self) -> bool

Check if task has custom priority (non-zero)

Source

pub const fn is_high_priority(&self) -> bool

Check if task has high priority (priority > 0)

Source

pub const fn is_low_priority(&self) -> bool

Check if task has low priority (priority < 0)

Source

pub fn with_dependency(self, dependency: TaskId) -> Self

Add a task dependency

Source

pub fn with_dependencies( self, dependencies: impl IntoIterator<Item = TaskId>, ) -> Self

Add multiple task dependencies

Source

pub fn has_dependencies(&self) -> bool

Check if task has any dependencies

Source

pub fn dependency_count(&self) -> usize

Get the number of dependencies

Source

pub fn depends_on(&self, task_id: &TaskId) -> bool

Check if a specific task is a dependency

Source

pub fn remove_dependency(&mut self, task_id: &TaskId) -> bool

Remove a dependency

Source

pub fn clear_dependencies(&mut self)

Clear all dependencies

Source

pub fn is_pending(&self) -> bool

Check if task is in Pending state

Source

pub fn is_running(&self) -> bool

Check if task is in Running state

Source

pub fn is_succeeded(&self) -> bool

Check if task is in Succeeded state

Source

pub fn is_failed(&self) -> bool

Check if task is in Failed state

Source

pub fn is_retrying(&self) -> bool

Check if task is in Retrying state

Source

pub fn is_reserved(&self) -> bool

Check if task is in Reserved state

Source

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());
}
Source

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);
Source

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());
Source

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);
Source

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);
Source

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());
Source

pub fn get_group_id(&self) -> Option<&Uuid>

Get group ID if task is part of a group

Source

pub fn get_chord_id(&self) -> Option<&Uuid>

Get chord ID if task is part of a chord

Source

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());
Source

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());
Source

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());
Source

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

Source§

fn clone(&self) -> TaskMetadata

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TaskMetadata

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for TaskMetadata

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for TaskMetadata

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Serialize for TaskMetadata

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,