を持っているデータベース接続を切断したいと思います。これはhttp
,express
、koa
と完全に機能します。独自のクリーンアップも追加したいので、パッケージを変更しました。これで、シャットダウン時に呼び出される独自のクリーンアップ機能を追加できるようになりました。私は `など優雅な再読み込みをサポートして生産のpm2`を、使用することをお勧めします
const koa = require('koa');
const gracefulShutdown = require('http-graceful-shutdown');
const app = new koa();
...
server = app.listen(...); // app can be an express OR koa app
...
// your personal cleanup function - this one takes one second to complete
function cleanup() {
return new Promise((resolve) => {
console.log('... in cleanup')
setTimeout(function() {
console.log('... cleanup finished');
resolve();
}, 1000)
});
}
// this enables the graceful shutdown with advanced options
gracefulShutdown(server,
{
signals: 'SIGINT SIGTERM',
timeout: 30000,
development: false,
onShutdown: cleanup,
finally: function() {
console.log('Server gracefulls shutted down.....')
}
}
);
:だから、基本的には、このパッケージには、すべてのhttpシャットダウン物事プラス(オプションで提供されている場合)あなたのクリーンアップ関数を呼び出しを処理します – zeronone