cloacina-workflow::namespace
Rust
Task namespace management for isolated task execution.
This module provides hierarchical namespace support for tasks, enabling:
- Multi-tenant task isolation
- Workflow package separation
- Conflict resolution between workflows with same task IDs
Namespace Format
Namespaces follow the format: tenant_id::package_name::workflow_id::task_id
tenant_id: Default “public”, can be tenant-specific for multi-tenancypackage_name: Default “embedded”, or name from .dylib/.so file metadataworkflow_id: From#[workflow]macro name attribute (required)task_id: From #[task] macro id parameter (required)
Examples:
use cloacina_workflow::TaskNamespace;
// Embedded workflow (most common)let ns = TaskNamespace::new("public", "embedded", "customer_etl", "extract_data");assert_eq!(ns.to_string(), "public::embedded::customer_etl::extract_data");
// Workflow packagelet ns = TaskNamespace::new("public", "analytics.so", "data_pipeline", "extract_data");assert_eq!(ns.to_string(), "public::analytics.so::data_pipeline::extract_data");
// Multi-tenant scenariolet ns = TaskNamespace::new("tenant_123", "embedded", "customer_etl", "extract_data");assert_eq!(ns.to_string(), "tenant_123::embedded::customer_etl::extract_data");Structs
Section titled “Structs”struct TaskNamespace
Section titled “struct TaskNamespace”pub
Derives: Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord
Hierarchical namespace for task identification and isolation.
Provides a structured way to identify tasks across different contexts: multi-tenant environments, workflow packages, and embedded workflows.
The namespace components form a hierarchy from most general (tenant) to most specific (task), enabling precise task resolution while supporting fallback strategies for compatibility.
Fields
Section titled “Fields”| Name | Type | Description |
|---|---|---|
tenant_id |
String |
Tenant identifier for multi-tenancy support. Default: “public” for single-tenant or public access |
package_name |
String |
Package or deployment context identifier. Default: “embedded” for tasks compiled into the binary For workflow packages: name from .dylib/.so file metadata |
workflow_id |
String |
Workflow identifier from workflow macro. Groups related tasks together within a package/tenant |
task_id |
String |
Individual task identifier from task macro. Unique within the workflow context |
Methods
Section titled “Methods”pub
fn new( tenant_id: &str, package_name: &str, workflow_id: &str, task_id: &str,) -> SelfCreate a complete namespace from all components.
This is the most general constructor, useful when all namespace components are known and need to be specified explicitly.
Parameters:
| Name | Type | Description |
|---|---|---|
tenant_id |
&str |
Tenant identifier |
package_name |
&str |
Package identifier |
workflow_id |
&str |
Workflow identifier |
task_id |
&str |
Task identifier |
Source
pub fn new(tenant_id: &str, package_name: &str, workflow_id: &str, task_id: &str) -> Self { Self { tenant_id: tenant_id.to_string(), package_name: package_name.to_string(), workflow_id: workflow_id.to_string(), task_id: task_id.to_string(), } }from_string
Section titled “from_string”pub
fn from_string(namespace_str: &str) -> Result<Self, String>Create a TaskNamespace from a string representation.
Parses a namespace string in the format “tenant::package::workflow::task” into a TaskNamespace struct.
Parameters:
| Name | Type | Description |
|---|---|---|
namespace_str |
&str |
String in format “tenant::package::workflow::task” |
Returns:
Result<TaskNamespace, String>- Successfully parsed namespace or error message
Examples:
use cloacina_workflow::TaskNamespace;
let ns = TaskNamespace::from_string("public::embedded::etl::extract").unwrap();assert_eq!(ns.tenant_id, "public");assert_eq!(ns.task_id, "extract");
// Invalid formatassert!(TaskNamespace::from_string("invalid_format").is_err());Source
pub fn from_string(namespace_str: &str) -> Result<Self, String> { parse_namespace(namespace_str) }is_public
Section titled “is_public”pub
fn is_public(&self) -> boolCheck if this is a public (non-tenant-specific) namespace.
Returns:
true if this namespace uses the default “public” tenant
Source
pub fn is_public(&self) -> bool { self.tenant_id == "public" }is_embedded
Section titled “is_embedded”pub
fn is_embedded(&self) -> boolCheck if this is an embedded (non-packaged) namespace.
Returns:
true if this namespace uses the default “embedded” package
Source
pub fn is_embedded(&self) -> bool { self.package_name == "embedded" }Functions
Section titled “Functions”fn parse_namespace
Section titled “fn parse_namespace”pub
fn parse_namespace(namespace_str: &str) -> Result<TaskNamespace, String>Parse a namespace string back into a TaskNamespace.
Supports parsing namespace strings in the standard format back into structured TaskNamespace objects.
Parameters:
| Name | Type | Description |
|---|---|---|
namespace_str |
&str |
String in format “tenant::package::workflow::task” |
Returns:
Ok(TaskNamespace)- Successfully parsed namespaceErr(String)- Parse error message
Examples:
use cloacina_workflow::parse_namespace;
let ns = parse_namespace("public::embedded::etl::extract").unwrap();assert_eq!(ns.tenant_id, "public");assert_eq!(ns.task_id, "extract");
// Invalid formatassert!(parse_namespace("invalid_format").is_err());Source
pub fn parse_namespace(namespace_str: &str) -> Result<TaskNamespace, String> { let parts: Vec<&str> = namespace_str.split("::").collect();
if parts.len() != 4 { return Err(format!( "Invalid namespace format '{}'. Expected 'tenant::package::workflow::task'", namespace_str )); }
Ok(TaskNamespace::new(parts[0], parts[1], parts[2], parts[3]))}