diff options
| author | Hazelnoot <acomputerdog@gmail.com> | 2025-02-16 19:13:08 -0500 |
|---|---|---|
| committer | Hazelnoot <acomputerdog@gmail.com> | 2025-03-21 12:37:06 -0400 |
| commit | 1ed2f207f7b711972bb57b20cb6653270dc77c97 (patch) | |
| tree | bc66589c2dcfdab06d7b4ad7f1e34b658cdc459b /packages/backend/src/core/UpdateInstanceQueue.ts | |
| parent | support Announce(Activity) activities (diff) | |
| download | sharkey-1ed2f207f7b711972bb57b20cb6653270dc77c97.tar.gz sharkey-1ed2f207f7b711972bb57b20cb6653270dc77c97.tar.bz2 sharkey-1ed2f207f7b711972bb57b20cb6653270dc77c97.zip | |
fix startup crash caused by circular reference (SWC is not compatible with forwardRef)
Diffstat (limited to 'packages/backend/src/core/UpdateInstanceQueue.ts')
| -rw-r--r-- | packages/backend/src/core/UpdateInstanceQueue.ts | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/packages/backend/src/core/UpdateInstanceQueue.ts b/packages/backend/src/core/UpdateInstanceQueue.ts new file mode 100644 index 0000000000..3fcd215ffa --- /dev/null +++ b/packages/backend/src/core/UpdateInstanceQueue.ts @@ -0,0 +1,52 @@ +/* + * SPDX-FileCopyrightText: syuilo and misskey-project + * SPDX-License-Identifier: AGPL-3.0-only + */ + +import { Injectable, OnApplicationShutdown } from '@nestjs/common'; +import { CollapsedQueue } from '@/misc/collapsed-queue.js'; +import { bindThis } from '@/decorators.js'; +import { MiNote } from '@/models/Note.js'; +import { FederatedInstanceService } from '@/core/FederatedInstanceService.js'; + +type UpdateInstanceJob = { + latestRequestReceivedAt: Date, + shouldUnsuspend: boolean, +}; + +// Moved from InboxProcessorService to allow access from ApInboxService +@Injectable() +export class UpdateInstanceQueue extends CollapsedQueue<MiNote['id'], UpdateInstanceJob> implements OnApplicationShutdown { + constructor( + private readonly federatedInstanceService: FederatedInstanceService, + ) { + super(process.env.NODE_ENV !== 'test' ? 60 * 1000 * 5 : 0, (id, job) => this.collapseUpdateInstanceJobs(id, job), (id, job) => this.performUpdateInstance(id, job)); + } + + @bindThis + private collapseUpdateInstanceJobs(oldJob: UpdateInstanceJob, newJob: UpdateInstanceJob) { + const latestRequestReceivedAt = oldJob.latestRequestReceivedAt < newJob.latestRequestReceivedAt + ? newJob.latestRequestReceivedAt + : oldJob.latestRequestReceivedAt; + const shouldUnsuspend = oldJob.shouldUnsuspend || newJob.shouldUnsuspend; + return { + latestRequestReceivedAt, + shouldUnsuspend, + }; + } + + @bindThis + private async performUpdateInstance(id: string, job: UpdateInstanceJob) { + await this.federatedInstanceService.update(id, { + latestRequestReceivedAt: new Date(), + isNotResponding: false, + // もしサーバーが死んでるために配信が止まっていた場合には自動的に復活させてあげる + suspensionState: job.shouldUnsuspend ? 'none' : undefined, + }); + } + + @bindThis + async onApplicationShutdown() { + await this.performAllNow(); + } +} |