Skip to main content

TaskChain

Struct TaskChain 

Source
pub struct TaskChain { /* private fields */ }
Expand description

Task chain configuration

§Examples

use reinhardt_tasks::TaskChain;

let chain = TaskChain::new("email-workflow");
assert_eq!(chain.name(), "email-workflow");

Implementations§

Source§

impl TaskChain

Source

pub fn new(name: impl Into<String>) -> Self

Create a new task chain

§Examples
use reinhardt_tasks::TaskChain;

let chain = TaskChain::new("payment-processing");
assert_eq!(chain.name(), "payment-processing");
Source

pub fn id(&self) -> TaskId

Get the chain ID

§Examples
use reinhardt_tasks::TaskChain;

let chain = TaskChain::new("test-chain");
let id = chain.id();
Source

pub fn name(&self) -> &str

Get the chain name

§Examples
use reinhardt_tasks::TaskChain;

let chain = TaskChain::new("my-chain");
assert_eq!(chain.name(), "my-chain");
Source

pub fn add_task(&mut self, task_id: TaskId)

Add a task to the chain

§Examples
use reinhardt_tasks::{TaskChain, TaskId};

let mut chain = TaskChain::new("workflow");
let task_id = TaskId::new();
chain.add_task(task_id);
assert_eq!(chain.task_count(), 1);
Source

pub fn task_count(&self) -> usize

Get the number of tasks in the chain

§Examples
use reinhardt_tasks::{TaskChain, TaskId};

let mut chain = TaskChain::new("workflow");
chain.add_task(TaskId::new());
chain.add_task(TaskId::new());
assert_eq!(chain.task_count(), 2);
Source

pub fn current_task(&self) -> Option<TaskId>

Get the current task ID

§Examples
use reinhardt_tasks::{TaskChain, TaskId};

let mut chain = TaskChain::new("workflow");
let task_id = TaskId::new();
chain.add_task(task_id);

assert_eq!(chain.current_task(), Some(task_id));
Source

pub fn advance(&mut self) -> bool

Move to the next task in the chain

Returns true if there are more tasks, false if the chain is complete.

§Examples
use reinhardt_tasks::{TaskChain, TaskId};

let mut chain = TaskChain::new("workflow");
chain.add_task(TaskId::new());
chain.add_task(TaskId::new());

assert!(chain.advance());
assert!(!chain.advance()); // No more tasks
Source

pub fn status(&self) -> ChainStatus

Get the chain status

§Examples
use reinhardt_tasks::{TaskChain, ChainStatus};

let chain = TaskChain::new("workflow");
assert_eq!(chain.status(), ChainStatus::Pending);
Source

pub fn set_status(&mut self, status: ChainStatus)

Set the chain status

§Examples
use reinhardt_tasks::{TaskChain, ChainStatus};

let mut chain = TaskChain::new("workflow");
chain.set_status(ChainStatus::Running);
assert_eq!(chain.status(), ChainStatus::Running);
Source

pub fn is_complete(&self) -> bool

Check if the chain is complete

§Examples
use reinhardt_tasks::{TaskChain, ChainStatus};

let mut chain = TaskChain::new("workflow");
chain.set_status(ChainStatus::Completed);
assert!(chain.is_complete());
Source

pub async fn execute( &mut self, backend: Arc<dyn TaskBackend>, ) -> Result<(), TaskExecutionError>

Execute the chain

This method will execute all tasks in the chain sequentially.

§Examples
use reinhardt_tasks::{TaskChain, DummyBackend};
use std::sync::Arc;

let mut chain = TaskChain::new("workflow");
let backend = Arc::new(DummyBackend::new());

chain.execute(backend).await?;
assert!(chain.is_complete());

Trait Implementations§

Source§

impl Clone for TaskChain

Source§

fn clone(&self) -> TaskChain

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 TaskChain

Source§

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

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

impl<'de> Deserialize<'de> for TaskChain

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 Serialize for TaskChain

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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
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, 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>,