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
impl Task
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>
pub async fn load( db: impl PgExecutor<'_>, tables: &dyn TaskTableProvider, id: Uuid, ) -> Result<Option<Self>>
pub async fn with_children( self, db: impl PgExecutor<'_>, tables: &dyn TaskTableProvider, recursive: bool, ) -> Result<Vec<Self>>
pub async fn children( &self, db: impl PgExecutor<'_>, tables: &dyn TaskTableProvider, recursive: bool, ) -> Result<Vec<Self>>
pub async fn load_children( db: impl PgExecutor<'_>, tables: &dyn TaskTableProvider, id: Uuid, include_self: bool, recursive: bool, ) -> Result<Vec<Self>>
pub async fn load_any_waiting( db: impl PgExecutor<'_>, tables: &dyn TaskTableProvider, allowed_types: &[impl TaskType], ) -> Result<Option<Self>>
pub async fn load_waiting( id: Uuid, db: impl PgExecutor<'_>, tables: &dyn TaskTableProvider, allowed_types: &[impl TaskType], ) -> Result<Option<Self>>
Sourcepub async fn set_error(
id: Uuid,
db: impl Acquire<'_, Database = Postgres>,
tables: &dyn TaskTableProvider,
error: Value,
) -> Result<()>
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
Sourcepub async fn save(
&self,
db: impl Acquire<'_, Database = Postgres>,
tables: &dyn TaskTableProvider,
) -> Result<()>
pub async fn save( &self, db: impl Acquire<'_, Database = Postgres>, tables: &dyn TaskTableProvider, ) -> Result<()>
Saves current state in DB
Sourcepub async fn update(
&mut self,
db: impl PgExecutor<'_>,
tables: &dyn TaskTableProvider,
) -> Result<()>
pub async fn update( &mut self, db: impl PgExecutor<'_>, tables: &dyn TaskTableProvider, ) -> Result<()>
Queries state of this task from DB and updates self.
Sourcepub async fn delete(
&self,
db: impl Acquire<'_, Database = Postgres>,
tables: &dyn TaskTableProvider,
) -> Result<()>
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.
Sourcepub async fn fullfill(
&mut self,
db: impl Acquire<'_, Database = Postgres>,
tables: &dyn TaskTableProvider,
result: Option<impl Into<Value>>,
error: Option<impl Into<Value>>,
) -> Result<()>
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
pub async fn wait_until_done( &mut self, db: &Pool<Postgres>, tables: &dyn TaskTableProvider, poll_interval: Option<Duration>, ) -> Result<()>
pub async fn wait_until_done_and_delete( &mut self, pool: &Pool<Postgres>, tables: &dyn TaskTableProvider, poll_interval: Option<Duration>, ) -> Result<()>
Sourcepub fn request<R: DeserializeOwned>(&mut self) -> Result<R>
pub fn request<R: DeserializeOwned>(&mut self) -> Result<R>
Takes request returns it deserialized.
Sourcepub fn result_cloned<R: DeserializeOwned>(&self) -> Result<Option<R>>
pub fn result_cloned<R: DeserializeOwned>(&self) -> Result<Option<R>>
Takes the result returns it deserialized.
Sourcepub fn as_result<R: DeserializeOwned>(&mut self) -> Result<Option<R>>
pub fn as_result<R: DeserializeOwned>(&mut self) -> Result<Option<R>>
Converts self into the result payload (or error).
Trait Implementations§
Source§impl<'a, R: Row> FromRow<'a, R> for Taskwhere
&'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>,
impl<'a, R: Row> FromRow<'a, R> for Taskwhere
&'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>,
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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