MCPcopy Create free account
hub / github.com/coder/mux / renewLease

Method renewLease

src/node/services/workflows/WorkflowRunStore.ts:736–760  ·  view source on GitHub ↗
(runId: string, ownerId: string, nowMs = Date.now())

Source from the content-addressed store, hash-verified

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);

Callers 2

runWithLeaseMethod · 0.80

Calls 7

leaseFileMethod · 0.95
readLeaseFunction · 0.85
writeJsonAtomicFunction · 0.85
assertFunction · 0.50

Tested by

no test coverage detected