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, andtask_routes: a list of routing rules in the form ofpattern => 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):
default_queue: Set theCeleryBuilder::default_queue.prefetch_count: Set theCeleryBuilder::prefect_count.heartbeat: Set theCeleryBuilder::heartbeat.task_time_limit: Set an app-levelTaskOptions::time_limit.task_hard_time_limit: Set an app-levelTaskOptions::hard_time_limit.task_max_retries: Set an app-levelTaskOptions::max_retries.task_min_retry_delay: Set an app-levelTaskOptions::min_retry_delay.task_max_retry_delay: Set an app-levelTaskOptions::max_retry_delay.task_retry_for_unexpected: Set an app-levelTaskOptions::retry_for_unexpected.acks_late: Set an app-levelTaskOptions::acks_late.result_backend: Set theCeleryBuilder::result_backend.broker_connection_timeout: Set theCeleryBuilder::broker_connection_timeout.broker_connection_retry: Set theCeleryBuilder::broker_connection_retry.broker_connection_max_retries: Set theCeleryBuilder::broker_connection_max_retries.
§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?;