From 2382aa44e138d897883e1bbdcf615bb60663060d Mon Sep 17 00:00:00 2001 From: softsimon Date: Sun, 1 Mar 2020 23:09:33 +0700 Subject: [PATCH] Write cache to disk on SIGTERM as with SIGINT. --- backend/src/api/disk-cache.ts | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/backend/src/api/disk-cache.ts b/backend/src/api/disk-cache.ts index 432e22922..30683f277 100644 --- a/backend/src/api/disk-cache.ts +++ b/backend/src/api/disk-cache.ts @@ -7,13 +7,22 @@ class DiskCache { constructor() { process.on('SIGINT', () => { - this.saveData(JSON.stringify({ - mempool: memPool.getMempool(), - blocks: blocks.getBlocks(), - })); - console.log('Mempool and blocks data saved to disk cache'); + this.saveCacheToDisk(); process.exit(2); }); + + process.on('SIGTERM', () => { + this.saveCacheToDisk(); + process.exit(2); + }); + } + + saveCacheToDisk() { + this.saveData(JSON.stringify({ + mempool: memPool.getMempool(), + blocks: blocks.getBlocks(), + })); + console.log('Mempool and blocks data saved to disk cache'); } loadMempoolCache() {