Skip to content

Commit fa17bc9

Browse files
committed
fix(core): exit child process while master process exited
1 parent 5d3cd6f commit fa17bc9

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

core.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ function spawnCronProcess () {
5151
process.on('exit', () => {
5252
// kill child process
5353
masterExitFlag = true
54-
child.exit()
54+
child.send({
55+
key: 'exit',
56+
data: ''
57+
})
5558
})
5659
child.on('exit', () => {
5760
if (!masterExitFlag) {

plugins.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict'
22
const path = require('path')
3+
const nconf = require('nconf')
4+
35
module.exports = [
46
// MiddleWares
57
require('./src/middlewares/requestId')(),
@@ -24,13 +26,12 @@ module.exports = [
2426
exposeHeaders: ['X-Request-Id']
2527
}),
2628
require('koa-favicon')(path.join(__dirname, './public/favicon.ico')),
27-
require('koa-compress')({
29+
!nconf.get('compress_body') || require('koa-compress')({
2830
filter: (contentType) => {
2931
return /text/i.test(contentType)
3032
},
3133
threshold: 2048,
3234
flush: require('zlib').Z_SYNC_FLUSH
3335
}),
3436
require('./src/logger')()
35-
3637
]

src/cron.js

+3
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ require('./prestart').load(null, true)
100100
process.on('message', message => {
101101
if (message.key === 'debug') {
102102
winston.level = 'verbose'
103+
} else if (message.key === 'exit') {
104+
winston.verbose('receive exit signal, cron process exiting.')
105+
process.exit()
103106
}
104107
})
105108
Cron.load()

0 commit comments

Comments
 (0)