1- import { dbReplica } from '@sim/db'
1+ import { db } from '@sim/db'
22import { workflowExecutionLogs } from '@sim/db/schema'
33import { createLogger } from '@sim/logger'
44import { and , avg , count , desc , eq , gte , ne , type SQL , sql } from 'drizzle-orm'
@@ -22,7 +22,7 @@ export function excludeSimExecutionsCondition(): SQL {
2222}
2323
2424async function checkConsecutiveFailures ( workflowId : string , threshold : number ) : Promise < boolean > {
25- const recentLogs = await dbReplica
25+ const recentLogs = await db
2626 . select ( { level : workflowExecutionLogs . level } )
2727 . from ( workflowExecutionLogs )
2828 . where ( and ( eq ( workflowExecutionLogs . workflowId , workflowId ) , excludeSimExecutionsCondition ( ) ) )
@@ -51,7 +51,7 @@ async function checkFailureRate(
5151
5252 // Single DB-side aggregate: the window is user-configured and this runs on
5353 // the execution-completion path, so never materialize the in-window rows.
54- const result = await dbReplica
54+ const result = await db
5555 . select ( {
5656 total : count ( ) ,
5757 errors : count ( sql `case when ${ workflowExecutionLogs . level } = 'error' then 1 end` ) ,
@@ -82,7 +82,7 @@ async function checkLatencySpike(
8282) : Promise < boolean > {
8383 const windowStart = new Date ( Date . now ( ) - windowHours * 60 * 60 * 1000 )
8484
85- const result = await dbReplica
85+ const result = await db
8686 . select ( {
8787 avgDuration : avg ( workflowExecutionLogs . totalDurationMs ) ,
8888 count : count ( ) ,
@@ -114,7 +114,7 @@ async function checkErrorCount(
114114) : Promise < boolean > {
115115 const windowStart = new Date ( Date . now ( ) - windowHours * 60 * 60 * 1000 )
116116
117- const result = await dbReplica
117+ const result = await db
118118 . select ( { count : count ( ) } )
119119 . from ( workflowExecutionLogs )
120120 . where (
0 commit comments