Struct Task

Source
pub struct Task {
    pub id: Uuid,
    pub parent: Option<Uuid>,
    pub created_at: DateTime<Utc>,
    pub updated_at: DateTime<Utc>,
    pub task_type: String,
    pub request: Option<Value>,
    pub result: Option<Value>,
    pub error: Option<Value>,
    pub in_progress: bool,
    pub done: bool,
}

Fields§

§id: Uuid§parent: Option<Uuid>§created_at: DateTime<Utc>§updated_at: DateTime<Utc>§task_type: String§request: Option<Value>§result: Option<Value>§error: Option<Value>§in_progress: bool§done: bool

Implementations§

Source§

impl Task

Source

pub async fn create_task<'a, DB, P>( db: DB, tables: &P, id: Option<Uuid>, task_type: String, req: Option<Value>, parent: Option<Uuid>, ) -> Result<Self>
where P: TaskTableProvider, DB: Acquire<'a, Database = Postgres>,

Source

pub async fn load( db: impl PgExecutor<'_>, tables: &dyn TaskTableProvider, id: Uuid, ) -> Result<Option<Self>>

Source

pub async fn with_children( self, db: impl PgExecutor<'_>, tables: &dyn TaskTableProvider, recursive: bool, ) -> Result<Vec<Self>>

Source

pub async fn children( &self, db: impl PgExecutor<'_>, tables: &dyn TaskTableProvider, recursive: bool, ) -> Result<Vec<Self>>

Source

pub async fn load_children( db: impl PgExecutor<'_>, tables: &dyn TaskTableProvider, id: Uuid, include_self: bool, recursive: bool, ) -> Result<Vec<Self>>

Source

pub async fn load_any_waiting( db: impl PgExecutor<'_>, tables: &dyn TaskTableProvider, allowed_types: &[impl TaskType], ) -> Result<Option<Self>>

Source

pub async fn load_waiting( id: Uuid, db: impl PgExecutor<'_>, tables: &dyn TaskTableProvider, allowed_types: &[impl TaskType], ) -> Result<Option<Self>>

Source

pub async fn set_error( id: Uuid, db: impl Acquire<'_, Database = Postgres>, tables: &dyn TaskTableProvider, error: Value, ) -> Result<()>

Sets the error value for the task

Source

pub async fn save( &self, db: impl Acquire<'_, Database = Postgres>, tables: &dyn TaskTableProvider, ) -> Result<()>

Saves current state in DB

Source

pub async fn update( &mut self, db: impl PgExecutor<'_>, tables: &dyn TaskTableProvider, ) -> Result<()>

Queries state of this task from DB and updates self.

Source

pub async fn delete( &self, db: impl Acquire<'_, Database = Postgres>, tables: &dyn TaskTableProvider, ) -> Result<()>

Deletes this and all child tasks (recursively) from the DB. Call this when the task is done.

Source

pub async fn fullfill( &mut self, db: impl Acquire<'_, Database = Postgres>, tables: &dyn TaskTableProvider, result: Option<impl Into<Value>>, error: Option<impl Into<Value>>, ) -> Result<()>

Fullfill task with result/error and mark as done

Source

pub async fn wait_until_done( &mut self, db: &Pool<Postgres>, tables: &dyn TaskTableProvider, poll_interval: Option<Duration>, ) -> Result<()>

Source

pub async fn wait_until_done_and_delete( &mut self, pool: &Pool<Postgres>, tables: &dyn TaskTableProvider, poll_interval: Option<Duration>, ) -> Result<()>

Source

pub fn request<R: DeserializeOwned>(&mut self) -> Result<R>

Takes request returns it deserialized.

Source

pub fn result_cloned<R: DeserializeOwned>(&self) -> Result<Option<R>>

Takes the result returns it deserialized.

Source

pub fn as_result<R: DeserializeOwned>(&mut self) -> Result<Option<R>>

Converts self into the result payload (or error).

Trait Implementations§

Source§

impl Clone for Task

Source§

fn clone(&self) -> Task

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 Task

Source§

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

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

impl<'a, R: Row> FromRow<'a, R> for Task
where &'a str: ColumnIndex<R>, Uuid: Decode<'a, R::Database> + Type<R::Database>, Option<Uuid>: Decode<'a, R::Database> + Type<R::Database>, DateTime<Utc>: Decode<'a, R::Database> + Type<R::Database>, String: Decode<'a, R::Database> + Type<R::Database>, Option<Value>: Decode<'a, R::Database> + Type<R::Database>, bool: Decode<'a, R::Database> + Type<R::Database>,

Source§

fn from_row(row: &'a R) -> Result<Self>

Auto Trait Implementations§

§

impl Freeze for Task

§

impl RefUnwindSafe for Task

§

impl Send for Task

§

impl Sync for Task

§

impl Unpin for Task

§

impl UnwindSafe for Task

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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> ErasedDestructor for T
where T: 'static,