* Shared dispatch loop for workflow lifecycle events: matches subscriptions * on event type and workflow scope, never notifying the source workflow about * itself. Fire-and-forget: failures never affect the lifecycle operation.
(params: {
eventType: 'workflow_deployed' | 'workflow_undeployed'
workflowId: string
workspaceId: string
payload: SimEventPayload
})
| 167 | * itself. Fire-and-forget: failures never affect the lifecycle operation. |
| 168 | */ |
| 169 | async function emitWorkflowLifecycleEvent(params: { |
| 170 | eventType: 'workflow_deployed' | 'workflow_undeployed' |
| 171 | workflowId: string |
| 172 | workspaceId: string |
| 173 | payload: SimEventPayload |
| 174 | }): Promise<void> { |
| 175 | try { |
| 176 | const subscriptions = await fetchSimTriggerSubscriptions(params.workspaceId) |
| 177 | if (subscriptions.length === 0) return |
| 178 | |
| 179 | for (const subscription of subscriptions) { |
| 180 | const config = parseSubscriptionConfig(subscription.webhook.providerConfig) |
| 181 | if (!config) continue |
| 182 | if (config.eventType !== params.eventType) continue |
| 183 | |
| 184 | if (subscription.webhook.workflowId === params.workflowId) continue |
| 185 | if (!matchesWorkflowScope(config, params.workflowId)) continue |
| 186 | |
| 187 | await dispatchSimEvent(subscription, params.payload) |
| 188 | } |
| 189 | } catch (error) { |
| 190 | logger.error(`Failed to emit ${params.eventType} event`, { |
| 191 | error, |
| 192 | workflowId: params.workflowId, |
| 193 | }) |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | /** |
| 198 | * Emits a workflow_deployed event to subscribed side-effect workflows. |
no test coverage detected