mirror of
https://iceshrimp.dev/crimekillz/iceshrimp-161sh.git
synced 2024-11-24 04:59:06 +01:00
25dedfb911
* Store nodeinfo per federated instances * Update fetch-nodeinfo.ts * Update fetch-nodeinfo.ts * update
27 lines
680 B
TypeScript
27 lines
680 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 getNodeinfoLock(host: string, timeout = 30 * 1000) {
|
|
return lock(`nodeinfo:${host}`, timeout);
|
|
}
|