Skip to content

Commit

Permalink
feat: disable graphile worker signal handling and add SIGTERM listeners
Browse files Browse the repository at this point in the history
  • Loading branch information
matthieu-foucault committed Jul 23, 2020
1 parent 4c5d791 commit 25f7be1
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion app/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,23 @@ const pgPool = new pg.Pool({connectionString: databaseURL});
// Graphile-worker function
async function worker() {
// Run a worker to execute jobs:
await run({
const runner = await run({
pgPool,
concurrency: 5,
pollInterval: 1000,
noHandleSignals: true,
taskDirectory: path.resolve(__dirname, 'tasks')
});

const sigtermHandler = async () => {
try {
await runner.stop();
} finally {
process.removeListener('SIGTERM', sigtermHandler);
}
};

process.addListener('SIGTERM', sigtermHandler);
}

// Start graphile-worker
Expand Down Expand Up @@ -406,4 +417,16 @@ app.prepare().then(() => {
console.log(`> Ready on http://localhost:${port}`);
});
}

process.on('SIGTERM', () => {
console.info('SIGTERM signal received.');
console.log('Closing http server.');
server.close(() => {
console.log('Http server closed.');
pgPool.end(() => {
console.log('Database connection closed.');
process.exit(0);
});
});
});
});

0 comments on commit 25f7be1

Please sign in to comment.