Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(backend): VRTL参加サーバーの取得に失敗したときのリトライの間隔を短く #38

Merged
merged 1 commit into from
Jun 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading