فهرست منبع

Simplified graceful shutdown

Efren Yevale Varela 1 ماه پیش
والد
کامیت
5d99a14a39
2فایلهای تغییر یافته به همراه3 افزوده شده و 26 حذف شده
  1. 0 12
      README.md
  2. 3 14
      src/hooks.server.js

+ 0 - 12
README.md

@@ -237,18 +237,6 @@ Database initialization is idempotent and runs only once when the database file
 
 Passwords are hashed using **Argon2id** (configured in `config.json`). Crypto utilities are available in `src/lib/crypto.js` for hashing and verification.
 
-## Exit Codes
-
-The application uses the following exit codes for process termination:
-
-| Code | Meaning | Trigger |
-|------|---------|---------|
-| `0` | Success / Graceful shutdown | `SIGTERM`, `SIGINT` signals |
-| `1` | Runtime error | Uncaught exceptions or unhandled promise rejections |
-| `2` | Cleanup error | Error during graceful shutdown cleanup logic |
-
-Exit codes are defined in `src/hooks.server.js` and are emitted when the process receives termination signals or encounters runtime errors.
-
 ## Links
 
 - [SvelteKit Documentation](https://svelte.dev/docs/kit)

+ 3 - 14
src/hooks.server.js

@@ -13,19 +13,8 @@ import { paraglideMiddleware } from '$lib/paraglide/server';
 
 export /** @type {import('@sveltejs/kit').Handle} */ const handle = handleParaglide;
 
-async function gracefulShutdown(exitCode = 0, signal = null) {
-  try {
-    if (config.database.type === 'sqlite3') {
-      closeSqlite3();
-    }
-  } catch (error) {
-    console.error('Error during cleanup:', error);
-    exitCode = 2;
-  }
-  process.exit(exitCode);
+async function gracefulShutdown() {
+  if (config.database.type === 'sqlite3') closeSqlite3();
 }
 
-process.on('SIGTERM',            ()               => gracefulShutdown(0, 'SIGTERM')            );
-process.on('SIGINT',             ()               => gracefulShutdown(0, 'SIGINT')             );
-process.on('uncaughtException',  (error)          => gracefulShutdown(1, 'uncaughtException')  );
-process.on('unhandledRejection', (reason,promise) => gracefulShutdown(1, 'unhandledRejection') );
+process.on('sveltekit:shutdown', async (reason) => gracefulShutdown() );