MCPcopy
hub / github.com/simstudioai/sim / claimCooldown

Function claimCooldown

apps/sim/lib/workspace-events/state.ts:41–67  ·  view source on GitHub ↗
(
  workflowId: string,
  blockId: string,
  scopeKey: string,
  cooldownMs: number
)

Source from the content-addressed store, hash-verified

39 * deployment version).
40 */
41export async function claimCooldown(
42 workflowId: string,
43 blockId: string,
44 scopeKey: string,
45 cooldownMs: number
46): Promise<boolean> {
47 const now = new Date()
48 const threshold = new Date(now.getTime() - cooldownMs)
49
50 const rows = await db
51 .insert(simTriggerState)
52 .values({
53 workflowId,
54 blockId,
55 scopeKey,
56 lastFiredAt: now,
57 updatedAt: now,
58 })
59 .onConflictDoUpdate({
60 target: [simTriggerState.workflowId, simTriggerState.blockId, simTriggerState.scopeKey],
61 set: { lastFiredAt: now, updatedAt: now },
62 setWhere: sql`${simTriggerState.lastFiredAt} IS NULL OR ${simTriggerState.lastFiredAt} < ${threshold}`,
63 })
64 .returning({ workflowId: simTriggerState.workflowId })
65
66 return rows.length > 0
67}
68
69export function isWithinCooldown(lastFiredAt: Date | null, cooldownMs: number): boolean {
70 if (!lastFiredAt) return false

Callers 2

checkWatchedWorkflowFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected