Trait celery::task::Task

source ·
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 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
; 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§

source

type Params: Clone + Send + Sync + Serialize + for<'de> Deserialize<'de>

The parameters of the task.

source

type Returns: Send + Sync + Debug

The return type of the task.

Required Associated Constants§

source

const NAME: &'static str

The name of the task. When a task is registered it will be registered with this name.

source

const ARGS: &'static [&'static str]

For compatability with Python tasks. This keeps track of the order of arguments for the task so that the task can be called from Python with positional arguments.

Provided Associated Constants§

source

const DEFAULTS: TaskOptions = _

Default task options.

Required Methods§

source

fn from_request(request: Request<Self>, options: TaskOptions) -> Self

Used to initialize a task instance from a request.

source

fn request(&self) -> &Request<Self>

Get a reference to the request used to create this task instance.

source

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).

source

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,

This function defines how a task executes.

Provided Methods§

source

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.

source

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.

source

fn name(&self) -> &'static str

Returns the registered name of the task.

source

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.

source

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.

source

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.

source

fn retry_for_unexpected(&self) -> bool

source

fn time_limit(&self) -> Option<u32>

source

fn max_retries(&self) -> Option<u32>

source

fn min_retry_delay(&self) -> u32

source

fn max_retry_delay(&self) -> u32

source

fn acks_late(&self) -> bool

Implementors§