Browse Source

fix Server is stopping only after second Ctrl-C #96

pull/1/head
Alexey Velikiy 6 years ago
parent
commit
0414ff4256
  1. 2
      server/src/controllers/analytics_controller.ts
  2. 6
      server/src/index.ts
  3. 1
      server/src/services/analytics_service.ts
  4. 3
      server/src/services/process_service.ts

2
server/src/controllers/analytics_controller.ts

@ -8,7 +8,7 @@ import { AnalyticsService, AnalyticsMessage } from '../services/analytics_servic
const taskMap = {};
let nextTaskId = 0;
let analyticsService = undefined;
let analyticsService: AnalyticsService = undefined;
function onTaskResult(taskResult: any) {

6
server/src/index.ts

@ -46,11 +46,7 @@ app
.use(rootRouter.routes())
.use(rootRouter.allowedMethods());
let server = app.listen(HASTIC_PORT, () => {
app.listen(HASTIC_PORT, () => {
console.log(`Server is running on :${HASTIC_PORT}`);
});
ProcessService.registerExitHandler(() => {
console.log('Stopping server...');
server.close();
})

1
server/src/services/analytics_service.ts

@ -70,6 +70,7 @@ export class AnalyticsService {
console.log('Terminating analytics service...');
clearInterval(this._analyticsPinger);
if(this._ipcPath !== null) {
console.log('Remove ipc path: ' + this._ipcPath);
fs.unlinkSync(this._ipcPath);
}
this._requester.close();

3
server/src/services/process_service.ts

@ -1,4 +1,5 @@
var exitHandlers = []
var exitHandled = false;
@ -19,6 +20,8 @@ function exitHandler(options, err) {
for(let i = 0; i < exitHandlers.length; i++) {
exitHandlers[i]();
}
console.log('process exit');
process.exit();
}
//do something when app is closing

Loading…
Cancel
Save