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: StringTask name
args: Vec<Value>Positional arguments
kwargs: HashMap<String, Value>Keyword arguments
options: TaskOptionsTask options
immutable: boolImmutability flag (whether args can be replaced)
Implementations§
Source§impl Signature
impl Signature
pub fn new(task: String) -> Signature
pub fn with_args(self, args: Vec<Value>) -> Signature
pub fn with_kwargs(self, kwargs: HashMap<String, Value>) -> Signature
pub fn with_priority(self, priority: u8) -> Signature
pub fn with_queue(self, queue: String) -> Signature
pub fn with_task_id(self, task_id: Uuid) -> Signature
pub fn with_link(self, link: Signature) -> Signature
pub fn with_link_error(self, link_error: Signature) -> Signature
Sourcepub fn add_link(self, link: Signature) -> Signature
pub fn add_link(self, link: Signature) -> Signature
Add a callback to the success callback chain
Sourcepub fn add_link_error(self, link_error: Signature) -> Signature
pub fn add_link_error(self, link_error: Signature) -> Signature
Add a callback to the error callback chain
Sourcepub fn with_on_retry(self, callback: Signature) -> Signature
pub fn with_on_retry(self, callback: Signature) -> Signature
Set the on_retry callback
Sourcepub fn with_soft_time_limit(self, seconds: u64) -> Signature
pub fn with_soft_time_limit(self, seconds: u64) -> Signature
Set soft time limit (warning before kill)
Sourcepub fn with_time_limit(self, seconds: u64) -> Signature
pub fn with_time_limit(self, seconds: u64) -> Signature
Set hard time limit (force kill)
Sourcepub fn with_retry_delay(self, seconds: u64) -> Signature
pub fn with_retry_delay(self, seconds: u64) -> Signature
Set retry delay in seconds
Sourcepub fn with_retry_backoff(self, factor: f64) -> Signature
pub fn with_retry_backoff(self, factor: f64) -> Signature
Set retry backoff factor (exponential multiplier)
Sourcepub fn with_retry_backoff_max(self, seconds: u64) -> Signature
pub fn with_retry_backoff_max(self, seconds: u64) -> Signature
Set maximum retry delay
Sourcepub fn with_retry_jitter(self, jitter: bool) -> Signature
pub fn with_retry_jitter(self, jitter: bool) -> Signature
Enable/disable retry jitter
pub fn immutable(self) -> Signature
Sourcepub fn has_kwargs(&self) -> bool
pub fn has_kwargs(&self) -> bool
Check if task has keyword arguments
Sourcepub fn is_immutable(&self) -> bool
pub fn is_immutable(&self) -> bool
Check if task is immutable (args cannot be replaced)
Sourcepub fn clone_signature(&self) -> Signature
pub fn clone_signature(&self) -> Signature
Clone the signature
Sourcepub fn si(self) -> Signature
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());Sourcepub fn partial(self, args: Vec<Value>) -> Signature
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);Sourcepub fn complete(self, additional_args: Vec<Value>) -> Signature
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.
Sourcepub fn merge(self, other: Signature) -> Signature
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.
Sourcepub fn replace_args(self, args: Vec<Value>) -> Option<Signature>
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.
Sourcepub fn with_expires(self, expires: u64) -> Signature
pub fn with_expires(self, expires: u64) -> Signature
Set expiration time in seconds
Sourcepub fn with_countdown(self, countdown: u64) -> Signature
pub fn with_countdown(self, countdown: u64) -> Signature
Set countdown (delay before execution) in seconds
Sourcepub fn with_retries(self, max_retries: u32) -> Signature
pub fn with_retries(self, max_retries: u32) -> Signature
Set retry policy
Sourcepub fn with_routing_key(self, routing_key: String) -> Signature
pub fn with_routing_key(self, routing_key: String) -> Signature
Set task routing key
Sourcepub fn with_callback_arg_mode(self, mode: CallbackArgMode) -> Signature
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);Sourcepub fn with_callback_kwarg_key(self, key: impl Into<String>) -> Signature
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.
Sourcepub fn with_result_as_kwarg(self, key: impl Into<String>) -> Signature
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.
Sourcepub fn from_json(json: &str) -> Result<Signature, Error>
pub fn from_json(json: &str) -> Result<Signature, Error>
Deserialize signature from JSON string
Sourcepub fn from_json_bytes(bytes: &[u8]) -> Result<Signature, Error>
pub fn from_json_bytes(bytes: &[u8]) -> Result<Signature, Error>
Deserialize signature from JSON bytes
Sourcepub fn clear_args(self) -> Option<Signature>
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());Sourcepub fn clear_kwargs(self) -> Signature
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());Sourcepub fn remove_kwarg(self, key: &str) -> Signature
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"));Sourcepub fn args_count(&self) -> usize
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);Sourcepub fn kwargs_count(&self) -> usize
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);Sourcepub fn kwarg_keys(&self) -> Vec<&str>
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"));Sourcepub fn has_retry_config(&self) -> bool
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());Sourcepub fn has_time_limit_config(&self) -> bool
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());Sourcepub fn clone_without_args(&self) -> Signature
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 preservedSourcepub fn estimated_size(&self) -> usize
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);