NodeJS cluster fix: Only save disk cache to disk when master.
fixes #108
This commit is contained in:
		
							parent
							
								
									d6744c07f9
								
							
						
					
					
						commit
						c2288c31e6
					
				@ -1,4 +1,5 @@
 | 
				
			|||||||
import * as fs from 'fs';
 | 
					import * as fs from 'fs';
 | 
				
			||||||
 | 
					import * as cluster from 'cluster';
 | 
				
			||||||
import memPool from './mempool';
 | 
					import memPool from './mempool';
 | 
				
			||||||
import blocks from './blocks';
 | 
					import blocks from './blocks';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -6,15 +7,17 @@ class DiskCache {
 | 
				
			|||||||
  static FILE_NAME = './cache.json';
 | 
					  static FILE_NAME = './cache.json';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  constructor() {
 | 
					  constructor() {
 | 
				
			||||||
    process.on('SIGINT', () => {
 | 
					    if (cluster.isMaster) {
 | 
				
			||||||
      this.saveCacheToDisk();
 | 
					      process.on('SIGINT', () => {
 | 
				
			||||||
      process.exit(2);
 | 
					        this.saveCacheToDisk();
 | 
				
			||||||
    });
 | 
					        process.exit(2);
 | 
				
			||||||
 | 
					      });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    process.on('SIGTERM', () => {
 | 
					      process.on('SIGTERM', () => {
 | 
				
			||||||
      this.saveCacheToDisk();
 | 
					        this.saveCacheToDisk();
 | 
				
			||||||
      process.exit(2);
 | 
					        process.exit(2);
 | 
				
			||||||
    });
 | 
					      });
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  saveCacheToDisk() {
 | 
					  saveCacheToDisk() {
 | 
				
			||||||
 | 
				
			|||||||
@ -7,7 +7,6 @@ import * as http from 'http';
 | 
				
			|||||||
import * as https from 'https';
 | 
					import * as https from 'https';
 | 
				
			||||||
import * as WebSocket from 'ws';
 | 
					import * as WebSocket from 'ws';
 | 
				
			||||||
import * as cluster from 'cluster';
 | 
					import * as cluster from 'cluster';
 | 
				
			||||||
import * as os from 'os';
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
import { checkDbConnection } from './database';
 | 
					import { checkDbConnection } from './database';
 | 
				
			||||||
import routes from './routes';
 | 
					import routes from './routes';
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user