mirror of
https://github.com/hotomoe/hotomoe
synced 2024-12-27 21:18:05 +09:00
f1ef85b636
* feat(server): Fetch icon url of an instance Resolve #6589 * chore: Rename the function
31 lines
821 B
TypeScript
31 lines
821 B
TypeScript
import redis from '../db/redis';
|
|
import { promisify } from 'util';
|
|
|
|
/**
|
|
* Retry delay (ms) for lock acquisition
|
|
*/
|
|
const retryDelay = 100;
|
|
|
|
const lock: (key: string, timeout?: number) => Promise<() => void>
|
|
= redis
|
|
? promisify(require('redis-lock')(redis, retryDelay))
|
|
: async () => () => { };
|
|
|
|
/**
|
|
* Get AP Object lock
|
|
* @param uri AP object ID
|
|
* @param timeout Lock timeout (ms), The timeout releases previous lock.
|
|
* @returns Unlock function
|
|
*/
|
|
export function getApLock(uri: string, timeout = 30 * 1000) {
|
|
return lock(`ap-object:${uri}`, timeout);
|
|
}
|
|
|
|
export function getFetchInstanceMetadataLock(host: string, timeout = 30 * 1000) {
|
|
return lock(`instance:${host}`, timeout);
|
|
}
|
|
|
|
export function getChartInsertLock(lockKey: string, timeout = 30 * 1000) {
|
|
return lock(`chart-insert:${lockKey}`, timeout);
|
|
}
|