mirror of
https://github.com/harivansh-afk/clanker-agent.git
synced 2026-04-21 03:04:28 +00:00
move pi-mono into companion-cloud as apps/companion-os
- Copy all pi-mono source into apps/companion-os/ - Update Dockerfile to COPY pre-built binary instead of downloading from GitHub Releases - Update deploy-staging.yml to build pi from source (bun compile) before Docker build - Add apps/companion-os/** to path triggers - No more cross-repo dispatch needed Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
commit
0250f72976
579 changed files with 206942 additions and 0 deletions
50
packages/pi-teams/src/utils/lock.ts
Normal file
50
packages/pi-teams/src/utils/lock.ts
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
// Project: pi-teams
|
||||
import fs from "node:fs";
|
||||
|
||||
const STALE_LOCK_TIMEOUT = 30000; // 30 seconds for a lock to be considered stale
|
||||
|
||||
export async function withLock<T>(
|
||||
lockPath: string,
|
||||
fn: () => Promise<T>,
|
||||
retries: number = 50,
|
||||
): Promise<T> {
|
||||
const lockFile = `${lockPath}.lock`;
|
||||
|
||||
while (retries > 0) {
|
||||
try {
|
||||
// Check if lock exists and is stale
|
||||
if (fs.existsSync(lockFile)) {
|
||||
const stats = fs.statSync(lockFile);
|
||||
const age = Date.now() - stats.mtimeMs;
|
||||
if (age > STALE_LOCK_TIMEOUT) {
|
||||
// Attempt to remove stale lock
|
||||
try {
|
||||
fs.unlinkSync(lockFile);
|
||||
} catch (_error) {
|
||||
// ignore, another process might have already removed it
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fs.writeFileSync(lockFile, process.pid.toString(), { flag: "wx" });
|
||||
break;
|
||||
} catch (_error) {
|
||||
retries--;
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
}
|
||||
}
|
||||
|
||||
if (retries === 0) {
|
||||
throw new Error("Could not acquire lock");
|
||||
}
|
||||
|
||||
try {
|
||||
return await fn();
|
||||
} finally {
|
||||
try {
|
||||
fs.unlinkSync(lockFile);
|
||||
} catch (_error) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue