From 83167623705848acd46c83b910a7f606714a6c53 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Thu, 12 Sep 2024 13:37:21 -0500 Subject: [PATCH] Remove this DittoExit stuff (since I'm not convinced it's needed) --- src/DittoExit.ts | 37 ------------------------------------- src/server.ts | 13 +------------ src/storages.ts | 3 --- 3 files changed, 1 insertion(+), 52 deletions(-) delete mode 100644 src/DittoExit.ts diff --git a/src/DittoExit.ts b/src/DittoExit.ts deleted file mode 100644 index 36201fc7..00000000 --- a/src/DittoExit.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { Stickynotes } from '@soapbox/stickynotes'; - -/** - * Add cleanup tasks to this module, - * then they will automatically be called (and the program exited) after SIGINT. - */ -export class DittoExit { - private static tasks: Array<() => Promise> = []; - private static console = new Stickynotes('ditto:exit'); - - static { - Deno.addSignalListener('SIGINT', () => this.finish('SIGINT')); - Deno.addSignalListener('SIGTERM', () => this.finish('SIGTERM')); - Deno.addSignalListener('SIGHUP', () => this.finish('SIGHUP')); - Deno.addSignalListener('SIGQUIT', () => this.finish('SIGQUIT')); - Deno.addSignalListener('SIGABRT', () => this.finish('SIGABRT')); - } - - static add(task: () => Promise): void { - this.tasks.push(task); - this.console.debug(`Added cleanup task #${this.tasks.length}`); - } - - private static async cleanup(): Promise { - this.console.debug(`Running ${this.tasks.length} cleanup tasks...`); - await Promise.allSettled( - this.tasks.map((task) => task()), - ); - } - - private static async finish(signal: Deno.Signal): Promise { - this.console.debug(signal); - await this.cleanup(); - this.console.debug('Exiting gracefully.'); - Deno.exit(0); - } -} diff --git a/src/server.ts b/src/server.ts index bfa240c9..f7a33dc0 100644 --- a/src/server.ts +++ b/src/server.ts @@ -5,16 +5,5 @@ import '@/sentry.ts'; import '@/nostr-wasm.ts'; import app from '@/app.ts'; import { Conf } from '@/config.ts'; -import { DittoExit } from '@/DittoExit.ts'; -const ac = new AbortController(); -// deno-lint-ignore require-await -DittoExit.add(async () => ac.abort()); - -Deno.serve( - { - port: Conf.port, - signal: ac.signal, - }, - app.fetch, -); +Deno.serve({ port: Conf.port }, app.fetch); diff --git a/src/storages.ts b/src/storages.ts index 15920444..05e2c383 100644 --- a/src/storages.ts +++ b/src/storages.ts @@ -2,7 +2,6 @@ import { Conf } from '@/config.ts'; import { DittoDatabase } from '@/db/DittoDatabase.ts'; import { DittoDB } from '@/db/DittoDB.ts'; -import { DittoExit } from '@/DittoExit.ts'; import { AdminStore } from '@/storages/AdminStore.ts'; import { EventsDB } from '@/storages/EventsDB.ts'; import { SearchStore } from '@/storages/search-store.ts'; @@ -11,8 +10,6 @@ import { NPool, NRelay1 } from '@nostrify/nostrify'; import { getRelays } from '@/utils/outbox.ts'; import { seedZapSplits } from '@/utils/zap-split.ts'; -DittoExit.add(() => Storages.close()); - export class Storages { private static _db: Promise | undefined; private static _database: Promise | undefined;