mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
Remove this DittoExit stuff (since I'm not convinced it's needed)
This commit is contained in:
parent
b3cfd5e12c
commit
8316762370
3 changed files with 1 additions and 52 deletions
|
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -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,
|
|
||||||
);
|
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue