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

Function acquireWorkflowMutationLock

src/node/services/workflows/WorkflowRunStore.ts:1213–1229  ·  view source on GitHub ↗
(
  lockDir: string,
  staleLeaseMs: number,
  timeoutMs = staleLeaseMs
)

Source from the content-addressed store, hash-verified

1211}
1212
1213async function acquireWorkflowMutationLock(
1214 lockDir: string,
1215 staleLeaseMs: number,
1216 timeoutMs = staleLeaseMs
1217): Promise<void> {
1218 const deadline = Date.now() + timeoutMs;
1219 while (Date.now() <= deadline) {
1220 if (await acquireLeaseMutationLock(lockDir, Date.now(), staleLeaseMs)) {
1221 return;
1222 }
1223 // Jittered backoff: a fixed sleep can phase-lock with the periodic lease renewal (whose
1224 // interval is also a small constant when staleLeaseMs is short, e.g. in tests), so every
1225 // retry lands while a renewal holds the lock and waiters starve for hundreds of ms.
1226 await new Promise((resolve) => setTimeout(resolve, 2 + Math.random() * 6));
1227 }
1228 throw new Error(`Timed out acquiring workflow mutation lock: ${lockDir}`);
1229}
1230
1231async function acquireLeaseMutationLock(
1232 lockDir: string,

Callers 5

createRunIfAbsentMethod · 0.85
renewLeaseMethod · 0.85
releaseLeaseMethod · 0.85

Calls 1

acquireLeaseMutationLockFunction · 0.85

Tested by

no test coverage detected