app

Macro app 

Source
macro_rules! app {
    (
        broker = $broker_type:ty { $broker_url:expr },
        tasks = [ $( $t:ty ),* $(,)? ],
        task_routes = [ $( $pattern:expr => $queue:expr ),* $(,)? ]
        $(, $x:ident = $y:expr )* $(,)?
    ) => { ... };
}
Expand description

A macro for creating a Celery app.

At a minimum the app! macro requires these 3 arguments (in order):

  • broker: a broker type (currently only AMQP is supported) with an expression for the broker URL in brackets,
  • tasks: a list of tasks to register, and
  • task_routes: a list of routing rules in the form of pattern => queue.

§Optional parameters

Following the task routing rules there are a number of other optional parameters that may appear in arbitrary order (all of which correspond to a method on the CeleryBuilder struct):

§Examples

use celery::prelude::*;

#[celery::task]
fn add(x: i32, y: i32) -> TaskResult<i32> {
    Ok(x + y)
}

let app = celery::app!(
    broker = AMQPBroker { std::env::var("AMQP_ADDR").unwrap() },
    tasks = [ add ],
    task_routes = [ "*" => "celery" ],
).await?;
let app = celery::app!(
    broker = AMQPBroker { std::env::var("AMQP_ADDR").unwrap() },
    tasks = [],
    task_routes = [],
    task_time_limit = 2
).await?;