lc_core/runnables/
config.rs1use serde_json::Value;
5use std::collections::HashMap;
6use std::sync::Arc;
7use uuid::Uuid;
8
9use lc_callbacks::CallbackManager;
10
11#[derive(Debug, Clone, Default)]
13pub struct RunnableConfig {
14 pub tags: Vec<String>,
16
17 pub metadata: HashMap<String, Value>,
19
20 pub max_concurrency: Option<usize>,
22
23 pub run_id: Option<Uuid>,
25
26 pub run_name: Option<String>,
28
29 pub callbacks: Option<Arc<CallbackManager>>,
31}
32
33impl RunnableConfig {
34 pub fn new() -> Self {
36 Self::default()
37 }
38
39 pub fn with_tag(mut self, tag: impl Into<String>) -> Self {
41 self.tags.push(tag.into());
42 self
43 }
44
45 pub fn with_metadata(mut self, key: impl Into<String>, value: Value) -> Self {
47 self.metadata.insert(key.into(), value);
48 self
49 }
50
51 pub fn with_max_concurrency(mut self, max: usize) -> Self {
53 self.max_concurrency = Some(max);
54 self
55 }
56
57 pub fn with_run_id(mut self, id: Uuid) -> Self {
59 self.run_id = Some(id);
60 self
61 }
62
63 pub fn with_run_name(mut self, name: impl Into<String>) -> Self {
65 self.run_name = Some(name.into());
66 self
67 }
68
69 pub fn with_callbacks(mut self, callbacks: Arc<CallbackManager>) -> Self {
71 self.callbacks = Some(callbacks);
72 self
73 }
74
75 pub fn merge(mut self, other: RunnableConfig) -> Self {
77 self.tags.extend(other.tags);
79 self.tags.sort();
80 self.tags.dedup();
81
82 self.metadata.extend(other.metadata);
84
85 if other.max_concurrency.is_some() {
87 self.max_concurrency = other.max_concurrency;
88 }
89 if other.run_id.is_some() {
90 self.run_id = other.run_id;
91 }
92 if other.run_name.is_some() {
93 self.run_name = other.run_name;
94 }
95 if other.callbacks.is_some() {
96 self.callbacks = other.callbacks;
97 }
98
99 self
100 }
101}