-
-
Notifications
You must be signed in to change notification settings - Fork 104
Expand file tree
/
Copy pathworker.js
More file actions
28 lines (21 loc) · 732 Bytes
/
worker.js
File metadata and controls
28 lines (21 loc) · 732 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
'use strict';
const worker = require('worker_threads');
const Application = require('./lib/application.js');
const application = new Application(worker);
application.on('started', () => {
application.logger.log(`Application started in worker ${worker.threadId}`);
});
worker.parentPort.on('message', async message => {
if (message.name === 'stop') {
if (application.finalization) return;
application.logger.log(`Graceful shutdown in worker ${worker.threadId}`);
await application.shutdown();
process.exit(0);
}
});
const logError = err => {
application.logger.error(err.stack);
};
process.on('uncaughtException', logError);
process.on('warning', logError);
process.on('unhandledRejection', logError);