Skip to main content

Signature

Struct Signature 

Source
pub struct Signature {
    pub task: String,
    pub args: Vec<Value>,
    pub kwargs: HashMap<String, Value>,
    pub options: TaskOptions,
    pub immutable: bool,
}
Expand description

Signature (a task definition with arguments)

Fields§

§task: String

Task name

§args: Vec<Value>

Positional arguments

§kwargs: HashMap<String, Value>

Keyword arguments

§options: TaskOptions

Task options

§immutable: bool

Immutability flag (whether args can be replaced)

Implementations§

Source§

impl Signature

Source

pub fn new(task: String) -> Signature

Source

pub fn with_args(self, args: Vec<Value>) -> Signature

Source

pub fn with_kwargs(self, kwargs: HashMap<String, Value>) -> Signature

Source

pub fn with_priority(self, priority: u8) -> Signature

Source

pub fn with_queue(self, queue: String) -> Signature

Source

pub fn with_task_id(self, task_id: Uuid) -> Signature

Add a callback to the success callback chain

Add a callback to the error callback chain

Source

pub fn with_on_retry(self, callback: Signature) -> Signature

Set the on_retry callback

Source

pub fn with_soft_time_limit(self, seconds: u64) -> Signature

Set soft time limit (warning before kill)

Source

pub fn with_time_limit(self, seconds: u64) -> Signature

Set hard time limit (force kill)

Source

pub fn with_retry_delay(self, seconds: u64) -> Signature

Set retry delay in seconds

Source

pub fn with_retry_backoff(self, factor: f64) -> Signature

Set retry backoff factor (exponential multiplier)

Source

pub fn with_retry_backoff_max(self, seconds: u64) -> Signature

Set maximum retry delay

Source

pub fn with_retry_jitter(self, jitter: bool) -> Signature

Enable/disable retry jitter

Source

pub fn immutable(self) -> Signature

Source

pub fn has_args(&self) -> bool

Check if task has arguments

Source

pub fn has_kwargs(&self) -> bool

Check if task has keyword arguments

Source

pub fn is_immutable(&self) -> bool

Check if task is immutable (args cannot be replaced)

Source

pub fn has_kwarg(&self, key: &str) -> bool

Check if task has a specific kwarg

Source

pub fn get_kwarg(&self, key: &str) -> Option<&Value>

Get a kwarg value

Source

pub fn add_kwarg(self, key: impl Into<String>, value: Value) -> Signature

Add a single kwarg

Source

pub fn add_arg(self, arg: Value) -> Signature

Add a single argument

Source

pub fn clone_signature(&self) -> Signature

Clone the signature

Source

pub fn si(self) -> Signature

Create an immutable signature (shorthand for .immutable())

This is equivalent to Python Celery’s .si() method. Immutable signatures cannot have their arguments replaced when used in workflows.

§Example
use celers_canvas::Signature;

let sig = Signature::new("process".to_string())
    .with_args(vec![serde_json::json!(1)])
    .si();

assert!(sig.is_immutable());
Source

pub fn partial(self, args: Vec<Value>) -> Signature

Create a partial signature with some arguments pre-filled

The partial signature can have additional arguments added later. This is useful for creating task templates with some fixed arguments.

§Example
use celers_canvas::Signature;

// Create a partial with first argument fixed
let partial = Signature::new("add".to_string())
    .partial(vec![serde_json::json!(10)]);

// Complete with remaining arguments
let complete = partial.complete(vec![serde_json::json!(5)]);
assert_eq!(complete.args.len(), 2);
Source

pub fn complete(self, additional_args: Vec<Value>) -> Signature

Complete a partial signature with additional arguments

Appends the provided arguments to the existing arguments. If the signature is immutable, returns the signature unchanged.

Source

pub fn merge(self, other: Signature) -> Signature

Merge another signature into this one

This combines kwargs from both signatures (the other’s kwargs take precedence) and inherits options from the other signature if not already set.

Source

pub fn replace_args(self, args: Vec<Value>) -> Option<Signature>

Replace arguments in signature (respects immutability)

If the signature is immutable, returns None. Otherwise, returns a new signature with replaced arguments.

Source

pub fn with_expires(self, expires: u64) -> Signature

Set expiration time in seconds

Source

pub fn with_countdown(self, countdown: u64) -> Signature

Set countdown (delay before execution) in seconds

Source

pub fn with_retries(self, max_retries: u32) -> Signature

Set retry policy

Source

pub fn with_routing_key(self, routing_key: String) -> Signature

Set task routing key

Source

pub fn with_callback_arg_mode(self, mode: CallbackArgMode) -> Signature

Set callback argument passing mode

Controls how task result is passed to linked callbacks.

§Example
use celers_canvas::{Signature, CallbackArgMode};

let sig = Signature::new("task".to_string())
    .with_callback_arg_mode(CallbackArgMode::Append);
Source

pub fn with_callback_kwarg_key(self, key: impl Into<String>) -> Signature

Set callback kwarg key (used when CallbackArgMode::Kwarg)

Specifies the keyword argument name for passing the result. Defaults to “result” if not set.

Source

pub fn with_result_as_kwarg(self, key: impl Into<String>) -> Signature

Configure callback to receive result as keyword argument

Shorthand for setting CallbackArgMode::Kwarg with a key.

Source

pub fn to_json(&self) -> Result<String, Error>

Serialize signature to JSON string

Source

pub fn from_json(json: &str) -> Result<Signature, Error>

Deserialize signature from JSON string

Source

pub fn to_json_bytes(&self) -> Result<Vec<u8>, Error>

Serialize signature to JSON bytes

Source

pub fn from_json_bytes(bytes: &[u8]) -> Result<Signature, Error>

Deserialize signature from JSON bytes

Source

pub fn clear_args(self) -> Option<Signature>

Clear all arguments from the signature

Returns None if the signature is immutable.

§Example
use celers_canvas::Signature;

let sig = Signature::new("task".to_string())
    .with_args(vec![serde_json::json!(1), serde_json::json!(2)]);

let cleared = sig.clear_args().unwrap();
assert!(cleared.args.is_empty());
Source

pub fn clear_kwargs(self) -> Signature

Clear all keyword arguments from the signature

§Example
use celers_canvas::Signature;
use std::collections::HashMap;

let mut kwargs = HashMap::new();
kwargs.insert("key".to_string(), serde_json::json!("value"));

let sig = Signature::new("task".to_string()).with_kwargs(kwargs);
let cleared = sig.clear_kwargs();
assert!(cleared.kwargs.is_empty());
Source

pub fn remove_kwarg(self, key: &str) -> Signature

Remove a specific keyword argument

§Example
use celers_canvas::Signature;

let sig = Signature::new("task".to_string())
    .add_kwarg("key1", serde_json::json!("value1"))
    .add_kwarg("key2", serde_json::json!("value2"));

let modified = sig.remove_kwarg("key1");
assert!(!modified.has_kwarg("key1"));
assert!(modified.has_kwarg("key2"));
Source

pub fn args_count(&self) -> usize

Get the number of positional arguments

§Example
use celers_canvas::Signature;

let sig = Signature::new("task".to_string())
    .with_args(vec![serde_json::json!(1), serde_json::json!(2)]);

assert_eq!(sig.args_count(), 2);
Source

pub fn kwargs_count(&self) -> usize

Get the number of keyword arguments

§Example
use celers_canvas::Signature;

let sig = Signature::new("task".to_string())
    .add_kwarg("key1", serde_json::json!("value1"))
    .add_kwarg("key2", serde_json::json!("value2"));

assert_eq!(sig.kwargs_count(), 2);
Source

pub fn kwarg_keys(&self) -> Vec<&str>

Get all keyword argument keys

§Example
use celers_canvas::Signature;

let sig = Signature::new("task".to_string())
    .add_kwarg("key1", serde_json::json!("value1"))
    .add_kwarg("key2", serde_json::json!("value2"));

let keys = sig.kwarg_keys();
assert_eq!(keys.len(), 2);
assert!(keys.contains(&"key1"));
assert!(keys.contains(&"key2"));
Source

pub fn has_retry_config(&self) -> bool

Check if signature has any retry configuration

§Example
use celers_canvas::Signature;

let sig1 = Signature::new("task".to_string()).with_retries(3);
let sig2 = Signature::new("task".to_string());

assert!(sig1.has_retry_config());
assert!(!sig2.has_retry_config());
Source

pub fn has_time_limit_config(&self) -> bool

Check if signature has any time limit configuration

§Example
use celers_canvas::Signature;

let sig1 = Signature::new("task".to_string()).with_time_limit(60);
let sig2 = Signature::new("task".to_string());

assert!(sig1.has_time_limit_config());
assert!(!sig2.has_time_limit_config());
Source

pub fn clone_without_args(&self) -> Signature

Create a new signature with the same task name but no arguments

§Example
use celers_canvas::Signature;

let sig = Signature::new("task".to_string())
    .with_args(vec![serde_json::json!(1)])
    .with_priority(5);

let clean = sig.clone_without_args();
assert_eq!(clean.task, "task");
assert!(clean.args.is_empty());
assert_eq!(clean.options.priority, Some(5)); // Options preserved
Source

pub fn estimated_size(&self) -> usize

Calculate the estimated serialized size in bytes

This gives a rough estimate of how much space the signature will take when serialized.

§Example
use celers_canvas::Signature;

let sig = Signature::new("task".to_string())
    .with_args(vec![serde_json::json!(1), serde_json::json!(2)]);

let size = sig.estimated_size();
assert!(size > 0);

Trait Implementations§

Source§

impl Clone for Signature

Source§

fn clone(&self) -> Signature

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Signature

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Signature

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<Signature, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Signature

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl From<Signature> for CanvasElement

Source§

fn from(sig: Signature) -> CanvasElement

Converts to this type from the input type.
Source§

impl FromIterator<Signature> for Chain

Source§

fn from_iter<T>(iter: T) -> Chain
where T: IntoIterator<Item = Signature>,

Creates a value from an iterator. Read more
Source§

impl FromIterator<Signature> for Group

Source§

fn from_iter<T>(iter: T) -> Group
where T: IntoIterator<Item = Signature>,

Creates a value from an iterator. Read more
Source§

impl PartialEq for Signature

Source§

fn eq(&self, other: &Signature) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Signature

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Signature

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> TaskArgs for T
where T: Serialize + DeserializeOwned + Send + Sync + 'static,

Source§

impl<T> TaskResult for T
where T: Serialize + DeserializeOwned + Send + 'static,