( workflowId: string, threshold: number, windowHours: number )
| 108 | } |
| 109 | |
| 110 | async function checkErrorCount( |
| 111 | workflowId: string, |
| 112 | threshold: number, |
| 113 | windowHours: number |
| 114 | ): Promise<boolean> { |
| 115 | const windowStart = new Date(Date.now() - windowHours * 60 * 60 * 1000) |
| 116 | |
| 117 | const result = await db |
| 118 | .select({ count: count() }) |
| 119 | .from(workflowExecutionLogs) |
| 120 | .where( |
| 121 | and( |
| 122 | eq(workflowExecutionLogs.workflowId, workflowId), |
| 123 | eq(workflowExecutionLogs.level, 'error'), |
| 124 | gte(workflowExecutionLogs.startedAt, windowStart), |
| 125 | excludeSimExecutionsCondition() |
| 126 | ) |
| 127 | ) |
| 128 | |
| 129 | const errorCount = result[0]?.count || 0 |
| 130 | return errorCount >= threshold |
| 131 | } |
| 132 | |
| 133 | /** |
| 134 | * Evaluates a rule-based event type against a completed execution. |
no test coverage detected