MCPcopy
hub / github.com/msgbyte/tianji / isLocked

Method isLocked

src/server/cache/distributedLock.ts:272–300  ·  view source on GitHub ↗

* Check if a lock is currently held * @param lockName - Name of the lock * @returns Promise - Whether the lock is currently held

(lockName: string)

Source from the content-addressed store, hash-verified

270 * @returns Promise<boolean> - Whether the lock is currently held
271 */
272 async isLocked(lockName: string): Promise<boolean> {
273 try {
274 const cacheManager = await getCacheManager();
275 const lockKey = `${this.options.prefix}:${lockName}`;
276 const existingLock = await cacheManager.get(lockKey);
277
278 if (!existingLock) {
279 return false;
280 }
281
282 const parsedLock = JSON.parse(String(existingLock));
283 const lockAge = Date.now() - parsedLock.acquiredAt;
284
285 // Check if lock has expired
286 if (lockAge > this.options.timeout) {
287 // Clean up expired lock
288 await cacheManager.delete(lockKey);
289 return false;
290 }
291
292 return true;
293 } catch (error) {
294 logger.error(
295 `[DistributedLock] Error checking lock status ${lockName}:`,
296 error
297 );
298 return false;
299 }
300 }
301
302 /**
303 * Get information about a lock

Callers

nothing calls this directly

Calls 6

getCacheManagerFunction · 0.85
parseMethod · 0.80
nowMethod · 0.80
errorMethod · 0.80
getMethod · 0.65
deleteMethod · 0.65

Tested by

no test coverage detected