pub trait Task: Send + Sync + Sized {
type Params: Clone + Send + Sync + Serialize + for<'de> Deserialize<'de>;
type Returns: Send + Sync + Debug;
const NAME: &'static str;
const ARGS: &'static [&'static str];
const DEFAULTS: TaskOptions = _;
Show 16 methods
// Required methods
fn from_request(request: Request<Self>, options: TaskOptions) -> Self;
fn request(&self) -> &Request<Self>;
fn options(&self) -> &TaskOptions;
fn run<'life0, 'async_trait>(
&'life0 self,
params: Self::Params
) -> Pin<Box<dyn Future<Output = TaskResult<Self::Returns>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
// Provided methods
fn on_failure<'life0, 'life1, 'async_trait>(
&'life0 self,
err: &'life1 TaskError
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
fn on_success<'life0, 'life1, 'async_trait>(
&'life0 self,
returned: &'life1 Self::Returns
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
fn name(&self) -> &'static str { ... }
fn retry_with_countdown(&self, countdown: u32) -> TaskResult<Self::Returns> { ... }
fn retry_with_eta(&self, eta: DateTime<Utc>) -> TaskResult<Self::Returns> { ... }
fn retry_eta(&self) -> Option<DateTime<Utc>> { ... }
fn retry_for_unexpected(&self) -> bool { ... }
fn time_limit(&self) -> Option<u32> { ... }
fn max_retries(&self) -> Option<u32> { ... }
fn min_retry_delay(&self) -> u32 { ... }
fn max_retry_delay(&self) -> u32 { ... }
fn acks_late(&self) -> bool { ... }
}Expand description
A Task represents a unit of work that a Celery app can produce or consume.
The recommended way to create tasks is through the task attribute macro, not by directly implementing
this trait. For more information see the tasks chapter
in the Rusty Celery Book.
Required Associated Types§
Required Associated Constants§
Provided Associated Constants§
sourceconst DEFAULTS: TaskOptions = _
const DEFAULTS: TaskOptions = _
Default task options.
Required Methods§
sourcefn from_request(request: Request<Self>, options: TaskOptions) -> Self
fn from_request(request: Request<Self>, options: TaskOptions) -> Self
Used to initialize a task instance from a request.
sourcefn request(&self) -> &Request<Self>
fn request(&self) -> &Request<Self>
Get a reference to the request used to create this task instance.
sourcefn options(&self) -> &TaskOptions
fn options(&self) -> &TaskOptions
Get a reference to the task’s configuration options.
This is a product of both app-level task options and the options configured specifically for the given task. Options specified at the task-level take priority over options specified at the app level. So, if the task was defined like this:
#[celery::task(time_limit = 3)]
fn add(x: i32, y: i32) -> TaskResult<i32> {
Ok(x + y)
}But the Celery app was built with a task_time_limit of 5, then
Task::options().time_limit would be Some(3).
Provided Methods§
sourcefn on_failure<'life0, 'life1, 'async_trait>(
&'life0 self,
err: &'life1 TaskError
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn on_failure<'life0, 'life1, 'async_trait>( &'life0 self, err: &'life1 TaskError ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,
Callback that will run after a task fails.
sourcefn on_success<'life0, 'life1, 'async_trait>(
&'life0 self,
returned: &'life1 Self::Returns
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn on_success<'life0, 'life1, 'async_trait>( &'life0 self, returned: &'life1 Self::Returns ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,
Callback that will run after a task completes successfully.
sourcefn retry_with_countdown(&self, countdown: u32) -> TaskResult<Self::Returns>
fn retry_with_countdown(&self, countdown: u32) -> TaskResult<Self::Returns>
This can be called from within a task function to trigger a retry in countdown seconds.
sourcefn retry_with_eta(&self, eta: DateTime<Utc>) -> TaskResult<Self::Returns>
fn retry_with_eta(&self, eta: DateTime<Utc>) -> TaskResult<Self::Returns>
This can be called from within a task function to trigger a retry at the specified eta.
sourcefn retry_eta(&self) -> Option<DateTime<Utc>>
fn retry_eta(&self) -> Option<DateTime<Utc>>
Get a future ETA at which time the task should be retried. By default this uses a capped exponential backoff strategy.