(runId: string, ownerId: string, nowMs = Date.now())
| 734 | } |
| 735 | |
| 736 | async renewLease(runId: string, ownerId: string, nowMs = Date.now()): Promise<boolean> { |
| 737 | assert(ownerId.length > 0, "WorkflowRunStore.renewLease: ownerId is required"); |
| 738 | const leaseFile = this.leaseFile(runId); |
| 739 | const lockDir = `${leaseFile}.lock`; |
| 740 | try { |
| 741 | await acquireWorkflowMutationLock( |
| 742 | lockDir, |
| 743 | this.leaseMutationLockStaleMs(), |
| 744 | this.leaseMutationWaitTimeoutMs() |
| 745 | ); |
| 746 | } catch { |
| 747 | return false; |
| 748 | } |
| 749 | |
| 750 | try { |
| 751 | const existing = await readLease(leaseFile); |
| 752 | if (existing?.ownerId !== ownerId) { |
| 753 | return false; |
| 754 | } |
| 755 | await writeJsonAtomic(leaseFile, { ownerId, acquiredAtMs: nowMs } satisfies LeaseRecord); |
| 756 | return true; |
| 757 | } finally { |
| 758 | await fs.rm(lockDir, { recursive: true, force: true }); |
| 759 | } |
| 760 | } |
| 761 | |
| 762 | async releaseLease(runId: string, ownerId: string): Promise<void> { |
| 763 | const leaseFile = this.leaseFile(runId); |
no test coverage detected