MCPcopy Create free account
hub / github.com/effect-app/libs / heartbeat

Function heartbeat

packages/infra/src/WorkflowEngineCosmos.ts:340–362  ·  view source on GitHub ↗
(executionId: string)

Source from the content-addressed store, hash-verified

338 * Best-effort: failures are swallowed; loop simply retries on next tick.
339 */
340 const heartbeat = (executionId: string): Effect.Effect<void> =>
341 Effect.gen(function*() {
342 while (true) {
343 yield* Effect.sleep(heartbeatInterval)
344 const local = locals.get(executionId)
345 const polled = local?.fiber?.pollUnsafe()
346 if (!local?.fiber || polled) return
347 const cur = yield* readExec(executionId).pipe(
348 Effect.catchCause(() => Effect.succeed(Option.none<ExecDoc>()))
349 )
350 if (Option.isNone(cur)) continue
351 const state = cur.value
352 if (state.status === "complete" || state.worker !== workerId) return
353 yield* replaceExec({
354 ...state,
355 leaseExpiresAt: new Date(Date.now() + Duration.toMillis(leaseTtl)).toISOString()
356 })
357 .pipe(
358 Effect.catchTag("OptimisticConcurrencyException", () => Effect.void),
359 Effect.catchCause(() => Effect.void)
360 )
361 }
362 })
363
364 // --- Drive logic -------------------------------------------------------
365

Callers 1

driveFunction · 0.70

Calls 7

pollUnsafeMethod · 0.80
readExecFunction · 0.70
replaceExecFunction · 0.70
sleepMethod · 0.65
getMethod · 0.65
pipeMethod · 0.65
succeedMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…