Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
repos
security
Test - Service Runner Fork - NodeJS
Commits
5b63975c
Commit
5b63975c
authored
Jun 12, 2020
by
Ppchelko
Committed by
Petr Pchelko
Jun 15, 2020
Browse files
Allow turning off worker heartbeat feature
Bug: T255278
parent
421d2f1b
Changes
5
Hide whitespace changes
Inline
Side-by-side
README.md
View file @
5b63975c
...
...
@@ -134,7 +134,7 @@ num_workers: ncpu
startup_concurrency
:
2
# Number of milliseconds to wait for a heartbeat from worker before killing
# and restarting
it
# and restarting
a worker. 'false' means disabling the heartbeat feature.
worker_heartbeat_timeout
:
7500
# Logger info
...
...
lib/base_service.js
View file @
5b63975c
...
...
@@ -11,6 +11,7 @@ const Logger = require('./logger');
const
docker
=
require
(
'
./docker
'
);
const
NUM_CPU_REGEX
=
/^
(?:(?:
ncpu
[\s
)*+-
/])
|
[\s
()*+-
/
.
\d])
+
(?:
ncpu
)?
$/
;
const
DEFAULT_WORKER_HEARTBEAT_TIMEOUT
=
7500
;
/**
* Abstract base class for Master and Worker classes.
...
...
@@ -288,7 +289,9 @@ class BaseService {
}
}
conf
.
startup_concurrency
=
conf
.
startup_concurrency
||
1
;
conf
.
worker_heartbeat_timeout
=
conf
.
worker_heartbeat_timeout
||
7500
;
if
(
!
conf
.
worker_heartbeat_timeout
&&
conf
.
worker_heartbeat_timeout
!==
false
)
{
conf
.
worker_heartbeat_timeout
=
DEFAULT_WORKER_HEARTBEAT_TIMEOUT
;
}
return
conf
;
}
...
...
lib/master.js
View file @
5b63975c
...
...
@@ -75,6 +75,7 @@ class Master extends BaseService {
super
.
stop
();
if
(
this
.
interval
)
{
clearInterval
(
this
.
interval
);
this
.
interval
=
undefined
;
}
this
.
_shuttingDown
=
true
;
this
.
_logger
.
log
(
'
info/service-runner/master
'
,
'
master shutting down, killing workers
'
);
...
...
@@ -110,7 +111,7 @@ class Master extends BaseService {
.
then
(()
=>
this
.
_startWorkers
(
this
.
config
.
num_workers
))
.
tap
(()
=>
{
this
.
_logger
.
log
(
'
warn/service-runner
'
,
'
startup finished
'
);
this
.
_
check
Heartbeat
();
this
.
_
setup
Heartbeat
Check
();
});
}
...
...
@@ -292,7 +293,10 @@ class Master extends BaseService {
* killing workers that were inactive for too long
* @private
*/
_checkHeartbeat
()
{
_setupHeartbeatCheck
()
{
if
(
this
.
config
.
worker_heartbeat_timeout
===
false
)
{
return
;
}
this
.
interval
=
setInterval
(()
=>
{
if
(
!
this
.
_shuttingDown
&&
!
this
.
_inRollingRestart
)
{
const
now
=
new
Date
();
...
...
lib/worker.js
View file @
5b63975c
...
...
@@ -156,7 +156,7 @@ class Worker extends BaseService {
this
.
_heapwatchHandle
.
setGCMonitor
();
if
(
cluster
.
isWorker
)
{
this
.
_
w
orkerHeartBeat
();
this
.
_
setupW
orkerHeartBeat
();
}
// Rate limiting.
...
...
@@ -220,7 +220,10 @@ class Worker extends BaseService {
});
}
_workerHeartBeat
()
{
_setupWorkerHeartBeat
()
{
if
(
this
.
config
.
worker_heartbeat_timeout
===
false
)
{
return
;
}
// We send heart beat 3 times more frequently than check it
// to avoid possibility of wrong restarts
if
(
this
.
_running
)
{
...
...
package.json
View file @
5b63975c
{
"name"
:
"service-runner"
,
"version"
:
"2.7.
7
"
,
"version"
:
"2.7.
8
"
,
"description"
:
"Generic nodejs service supervisor / cluster runner"
,
"main"
:
"service-runner.js"
,
"bin"
:
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment