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,
)
| 122 | /// - `$collection` → the collection name |
| 123 | /// - `$operation` → "insert", "update", or "delete" |
| 124 | async 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 | } |
no test coverage detected