* Checks one watched workflow and fires when it has gone quiet, accumulating * counts into `result`.
(
subscription: SimSubscription,
config: SimSubscriptionConfig,
sourceWorkflow: { id: string; name: string },
result: NoActivityPollResult
)
| 149 | * counts into `result`. |
| 150 | */ |
| 151 | async function checkWatchedWorkflow( |
| 152 | subscription: SimSubscription, |
| 153 | config: SimSubscriptionConfig, |
| 154 | sourceWorkflow: { id: string; name: string }, |
| 155 | result: NoActivityPollResult |
| 156 | ): Promise<void> { |
| 157 | result.checked++ |
| 158 | |
| 159 | const blockKey = subscription.webhook.blockId ?? subscription.webhook.path |
| 160 | const cooldownMs = noActivityCooldownMs(config) |
| 161 | |
| 162 | const lastFiredAt = await readLastFiredAt( |
| 163 | subscription.webhook.workflowId, |
| 164 | blockKey, |
| 165 | sourceWorkflow.id |
| 166 | ) |
| 167 | if (isWithinCooldown(lastFiredAt, cooldownMs)) { |
| 168 | result.skipped++ |
| 169 | return |
| 170 | } |
| 171 | |
| 172 | if (await hasRecentActivity(sourceWorkflow.id, config)) { |
| 173 | result.skipped++ |
| 174 | return |
| 175 | } |
| 176 | |
| 177 | const claimed = await claimCooldown( |
| 178 | subscription.webhook.workflowId, |
| 179 | blockKey, |
| 180 | sourceWorkflow.id, |
| 181 | cooldownMs |
| 182 | ) |
| 183 | if (!claimed) { |
| 184 | result.skipped++ |
| 185 | return |
| 186 | } |
| 187 | |
| 188 | const payload = buildNoActivityEventPayload({ |
| 189 | workflowId: sourceWorkflow.id, |
| 190 | workflowName: sourceWorkflow.name, |
| 191 | }) |
| 192 | |
| 193 | await dispatchSimEvent(subscription, payload) |
| 194 | result.fired++ |
| 195 | |
| 196 | logger.info(`no_activity event fired for workflow ${sourceWorkflow.id}`, { |
| 197 | subscriberWorkflowId: subscription.webhook.workflowId, |
| 198 | inactivityHours: config.inactivityHours, |
| 199 | }) |
| 200 | } |
| 201 | |
| 202 | /** |
| 203 | * Checks a single no_activity subscription's watched workflows and fires |
no test coverage detected