頻繁にAPリクエストが発生するサーバーに対してfetchInstanceMetadata手動更新が無視される問題を修正 (MisskeyIO#194)
This commit is contained in:
parent
239d9a4c81
commit
42bc2817be
2 changed files with 7 additions and 6 deletions
|
@ -52,20 +52,20 @@ export class FetchInstanceMetadataService {
|
|||
|
||||
@bindThis
|
||||
public async tryLock(host: string): Promise<boolean> {
|
||||
const mutex = await this.redisClient.set(`fetchInstanceMetadata:mutex:${host}`, '1', 'EX', 60 * 5, 'NX', 'GET');
|
||||
return mutex !== '1';
|
||||
const mutex = await this.redisClient.set(`fetchInstanceMetadata:mutex:${host}`, Date.now(), 'EX', 60 * 5, 'NX');
|
||||
return mutex !== null;
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public unlock(host: string): Promise<number> {
|
||||
return this.redisClient.del(`fetchInstanceMetadata:mutex:${host}`);
|
||||
return this.redisClient.unlink(`fetchInstanceMetadata:mutex:${host}`);
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async fetchInstanceMetadata(instance: MiInstance, force = false): Promise<void> {
|
||||
const host = instance.host;
|
||||
// Acquire mutex to ensure no parallel runs
|
||||
if (!await this.tryLock(host)) return;
|
||||
if (!await this.tryLock(host) && !force) return;
|
||||
try {
|
||||
if (!force) {
|
||||
const _instance = await this.federatedInstanceService.fetch(host);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue