Skip to content

Commit

Permalink
chore(backend): VRTL参加サーバーの取得に失敗したときのリトライの間隔を短く (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
anatawa12 authored Jun 16, 2024
1 parent 24be6b1 commit 1dd7398
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-VRTL.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
VRTLのブランチで行われた変更点をまとめています

<!-- VV Please add changelog here VV -->
- chore(backend): VRTL参加サーバーの取得に失敗したときのリトライの間隔を短く
- feat: VRTL/VSTLに連合なし投稿を含めるかを選択可能に
- もともとのVRTL/VSTLでは連合なし投稿が常に含まれていましたが、正しくVRTL/VSTLのノートを表現するために含めないようにできるようになりました
- VSTLの場合、連合なし投稿を含めないようにしてもフォローしている人の連合なし投稿は表示されます
Expand Down
13 changes: 9 additions & 4 deletions packages/backend/src/core/VmimiRelayTimelineService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ import type Logger from '@/logger.js';
type VmimiInstanceList = { Url: string; }[];

// one day
const UpdateInterval = 1000 * 60 * 60 * 24;
const RetryInterval = 1000 * 60 * 60 * 6;
const UpdateInterval = 1000 * 60 * 60 * 24; // 24 hours = 1 day
const MinRetryInterval = 1000 * 60; // one minutes
const MaxRetryInterval = 1000 * 60 * 60 * 6; // 6 hours

@Injectable()
export class VmimiRelayTimelineService {
instanceHosts: Set<string>;
instanceHostsArray: string[];
nextUpdate: number;
nextRetryInterval: number;
updatePromise: Promise<void> | null;
private logger: Logger;

Expand All @@ -32,6 +34,7 @@ export class VmimiRelayTimelineService {
this.instanceHosts = new Set<string>([]);
this.instanceHostsArray = [];
this.nextUpdate = 0;
this.nextRetryInterval = MinRetryInterval;
this.updatePromise = null;

this.logger = this.loggerService.getLogger('vmimi');
Expand All @@ -55,10 +58,12 @@ export class VmimiRelayTimelineService {
this.instanceHosts = new Set<string>(this.instanceHostsArray);
this.nextUpdate = Date.now() + UpdateInterval;
this.logger.info(`Got instance list: ${this.instanceHostsArray}`);
this.nextRetryInterval = MinRetryInterval;
} catch (e) {
this.logger.error('Failed to update instance list', e as any);
this.nextUpdate = Date.now() + RetryInterval;
setTimeout(() => this.checkForUpdateInstanceList(), RetryInterval + 5);
this.nextUpdate = Date.now() + this.nextRetryInterval;
setTimeout(() => this.checkForUpdateInstanceList(), this.nextRetryInterval + 5);
this.nextRetryInterval = Math.min(this.nextRetryInterval * 2, MaxRetryInterval);
}
}

Expand Down

0 comments on commit 1dd7398

Please sign in to comment.