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

Function tryClaim

packages/infra/src/WorkflowEngineCosmos.ts:321–334  ·  view source on GitHub ↗
(state: ExecDoc)

Source from the content-addressed store, hash-verified

319 * retry by re-reading).
320 */
321 const tryClaim = (state: ExecDoc): Effect.Effect<Option.Option<ExecDoc>> =>
322 Effect.gen(function*() {
323 const now = Date.now()
324 if (leaseActive(state, now)) return Option.none<ExecDoc>()
325 const updated: ExecDoc = {
326 ...state,
327 worker: workerId,
328 leaseExpiresAt: new Date(now + Duration.toMillis(leaseTtl)).toISOString()
329 }
330 return yield* replaceExec(updated).pipe(
331 Effect.map(Option.some),
332 Effect.catchTag("OptimisticConcurrencyException", () => Effect.succeed(Option.none<ExecDoc>()))
333 )
334 })
335
336 /**
337 * Renew lease until the local fiber stops or another worker takes the claim.

Callers 1

driveFunction · 0.70

Calls 5

leaseActiveFunction · 0.70
replaceExecFunction · 0.70
pipeMethod · 0.65
mapMethod · 0.65
succeedMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…