MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / execute_then_action

Function execute_then_action

nodedb/src/control/event_trigger.rs:124–179  ·  view source on GitHub ↗

Execute a THEN action string as SQL. Template variables are substituted before execution: - `$document_id` → the affected document ID - `$collection` → the collection name - `$operation` → "insert", "update", or "delete"

(
    shared: &SharedState,
    event: &ChangeEvent,
    action: &str,
    trigger_name: &str,
)

Source from the content-addressed store, hash-verified

122/// - `$collection` → the collection name
123/// - `$operation` → "insert", "update", or "delete"
124async fn execute_then_action(
125 shared: &SharedState,
126 event: &ChangeEvent,
127 action: &str,
128 trigger_name: &str,
129) {
130 let sql = action
131 .replace("$document_id", &event.document_id)
132 .replace("$collection", &event.collection)
133 .replace("$operation", event.operation.as_str());
134
135 let query_ctx = QueryContext::for_state(shared);
136
137 match query_ctx
138 .plan_sql(&sql, event.tenant_id, crate::types::DatabaseId::DEFAULT)
139 .await
140 {
141 Ok(tasks) => {
142 for task in tasks {
143 match crate::control::server::dispatch_utils::dispatch_to_data_plane(
144 shared,
145 task.tenant_id,
146 task.vshard_id,
147 task.plan,
148 TraceId::ZERO,
149 )
150 .await
151 {
152 Ok(_) => {
153 info!(
154 trigger = trigger_name,
155 sql = sql,
156 "event trigger action executed"
157 );
158 }
159 Err(e) => {
160 warn!(
161 trigger = trigger_name,
162 sql = sql,
163 error = %e,
164 "event trigger action dispatch failed"
165 );
166 }
167 }
168 }
169 }
170 Err(e) => {
171 warn!(
172 trigger = trigger_name,
173 sql = sql,
174 error = %e,
175 "event trigger action plan failed"
176 );
177 }
178 }
179}

Callers 1

process_eventFunction · 0.85

Calls 4

replaceMethod · 0.80
plan_sqlMethod · 0.80
dispatch_to_data_planeFunction · 0.50
as_strMethod · 0.45

Tested by

no test coverage detected