Remove this DittoExit stuff (since I'm not convinced it's needed)

This commit is contained in:
Alex Gleason 2024-09-12 13:37:21 -05:00
parent b3cfd5e12c
commit 8316762370
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
3 changed files with 1 additions and 52 deletions

View file

@ -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<unknown>> = [];
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<unknown>): void {
this.tasks.push(task);
this.console.debug(`Added cleanup task #${this.tasks.length}`);
}
private static async cleanup(): Promise<void> {
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<void> {
this.console.debug(signal);
await this.cleanup();
this.console.debug('Exiting gracefully.');
Deno.exit(0);
}
}

View file

@ -5,16 +5,5 @@ import '@/sentry.ts';
import '@/nostr-wasm.ts'; import '@/nostr-wasm.ts';
import app from '@/app.ts'; import app from '@/app.ts';
import { Conf } from '@/config.ts'; import { Conf } from '@/config.ts';
import { DittoExit } from '@/DittoExit.ts';
const ac = new AbortController(); Deno.serve({ port: Conf.port }, app.fetch);
// deno-lint-ignore require-await
DittoExit.add(async () => ac.abort());
Deno.serve(
{
port: Conf.port,
signal: ac.signal,
},
app.fetch,
);

View file

@ -2,7 +2,6 @@
import { Conf } from '@/config.ts'; import { Conf } from '@/config.ts';
import { DittoDatabase } from '@/db/DittoDatabase.ts'; import { DittoDatabase } from '@/db/DittoDatabase.ts';
import { DittoDB } from '@/db/DittoDB.ts'; import { DittoDB } from '@/db/DittoDB.ts';
import { DittoExit } from '@/DittoExit.ts';
import { AdminStore } from '@/storages/AdminStore.ts'; import { AdminStore } from '@/storages/AdminStore.ts';
import { EventsDB } from '@/storages/EventsDB.ts'; import { EventsDB } from '@/storages/EventsDB.ts';
import { SearchStore } from '@/storages/search-store.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 { getRelays } from '@/utils/outbox.ts';
import { seedZapSplits } from '@/utils/zap-split.ts'; import { seedZapSplits } from '@/utils/zap-split.ts';
DittoExit.add(() => Storages.close());
export class Storages { export class Storages {
private static _db: Promise<EventsDB> | undefined; private static _db: Promise<EventsDB> | undefined;
private static _database: Promise<DittoDatabase> | undefined; private static _database: Promise<DittoDatabase> | undefined;