(state: ExecDoc)
| 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. |
no test coverage detected
searching dependent graphs…