MCPcopy Index your code
hub / github.com/simstudioai/sim / checkLatencySpike

Function checkLatencySpike

apps/sim/lib/workspace-events/rules.ts:77–108  ·  view source on GitHub ↗
(
  workflowId: string,
  currentDurationMs: number,
  spikePercent: number,
  windowHours: number
)

Source from the content-addressed store, hash-verified

75}
76
77async function checkLatencySpike(
78 workflowId: string,
79 currentDurationMs: number,
80 spikePercent: number,
81 windowHours: number
82): Promise<boolean> {
83 const windowStart = new Date(Date.now() - windowHours * 60 * 60 * 1000)
84
85 const result = await db
86 .select({
87 avgDuration: avg(workflowExecutionLogs.totalDurationMs),
88 count: count(),
89 })
90 .from(workflowExecutionLogs)
91 .where(
92 and(
93 eq(workflowExecutionLogs.workflowId, workflowId),
94 gte(workflowExecutionLogs.startedAt, windowStart),
95 excludeSimExecutionsCondition()
96 )
97 )
98
99 const avgDuration = result[0]?.avgDuration
100 const execCount = result[0]?.count || 0
101
102 if (!avgDuration || execCount < SIM_MIN_EXECUTIONS_FOR_RATE_RULES) return false
103
104 const avgMs = Number(avgDuration)
105 const threshold = avgMs * (1 + spikePercent / 100)
106
107 return currentDurationMs > threshold
108}
109
110async function checkErrorCount(
111 workflowId: string,

Callers 1

evaluateRuleFunction · 0.85

Calls 2

eqFunction · 0.50

Tested by

no test coverage detected