use serde_json::Value;
use std::collections::HashMap;
use std::sync::Arc;
use uuid::Uuid;
use crate::callbacks::CallbackManager;
#[derive(Debug, Clone, Default)]
pub struct RunnableConfig {
pub tags: Vec<String>,
pub metadata: HashMap<String, Value>,
pub max_concurrency: Option<usize>,
pub run_id: Option<Uuid>,
pub run_name: Option<String>,
pub callbacks: Option<Arc<CallbackManager>>,
}
impl RunnableConfig {
pub fn new() -> Self {
Self::default()
}
pub fn with_tag(mut self, tag: impl Into<String>) -> Self {
self.tags.push(tag.into());
self
}
pub fn with_metadata(mut self, key: impl Into<String>, value: Value) -> Self {
self.metadata.insert(key.into(), value);
self
}
pub fn with_max_concurrency(mut self, max: usize) -> Self {
self.max_concurrency = Some(max);
self
}
pub fn with_run_id(mut self, id: Uuid) -> Self {
self.run_id = Some(id);
self
}
pub fn with_run_name(mut self, name: impl Into<String>) -> Self {
self.run_name = Some(name.into());
self
}
pub fn with_callbacks(mut self, callbacks: Arc<CallbackManager>) -> Self {
self.callbacks = Some(callbacks);
self
}
pub fn merge(mut self, other: RunnableConfig) -> Self {
self.tags.extend(other.tags);
self.tags.sort();
self.tags.dedup();
self.metadata.extend(other.metadata);
if other.max_concurrency.is_some() {
self.max_concurrency = other.max_concurrency;
}
if other.run_id.is_some() {
self.run_id = other.run_id;
}
if other.run_name.is_some() {
self.run_name = other.run_name;
}
if other.callbacks.is_some() {
self.callbacks = other.callbacks;
}
self
}
}