dcp-worker 4.1.1 → 4.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitlab-ci.yml +1 -3
- package/bin/dcp-evaluator-manager +33 -15
- package/bin/dcp-evaluator-start +149 -119
- package/bin/dcp-task-probe +20 -11
- package/bin/dcp-worker +698 -578
- package/lib/blessed-components/log.js +10 -0
- package/lib/check-scheduler-version.js +3 -2
- package/lib/consts.js +25 -0
- package/lib/loggers.js +256 -0
- package/lib/node-version-check.js +4 -2
- package/lib/pidfile.js +88 -4
- package/lib/reports.js +95 -0
- package/lib/show.js +54 -0
- package/lib/{remote-console.js → telnetd.js} +32 -19
- package/lib/utils.js +112 -9
- package/lib/web-console.js +178 -0
- package/lib/web-iface.js +128 -0
- package/lib/{dashboard-tui.js → worker-consoles/dashboard-console.js} +167 -57
- package/lib/worker-consoles/index.js +44 -0
- package/lib/worker-consoles/none-console.js +23 -0
- package/lib/worker-consoles/stdio-console.js +70 -0
- package/lib/worker-info.js +29 -20
- package/lib/worker-loggers/event-log.js +24 -26
- package/lib/worker-loggers/logfile.js +73 -65
- package/lib/worker-loggers/syslog.js +145 -43
- package/package.json +6 -4
- package/{bin/publish-docs.sh → publish-docs.sh} +1 -1
- package/tests/worker-with-no-options.simple +35 -13
- package/tests/worker-with-options.simple +65 -18
- package/lib/startWorkerLogger.js +0 -138
- package/lib/worker-loggers/console.js +0 -74
- package/lib/worker-loggers/dashboard.js +0 -76
package/lib/startWorkerLogger.js
DELETED
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file startWorkerLogger.js
|
|
3
|
-
* Start the DCP Worker logging subsystem. Sets console.log (etc) redirection, determine
|
|
4
|
-
* the correct log target (screen, TUI, syslog, windows event log, file) and redirect the
|
|
5
|
-
* output there.
|
|
6
|
-
* @author Ryan Rossiter, ryan@kingsds.network
|
|
7
|
-
* @date April 2020
|
|
8
|
-
* @author Wes Garland, wes@distributive.network
|
|
9
|
-
*/
|
|
10
|
-
'use strict';
|
|
11
|
-
|
|
12
|
-
const process = require('process');
|
|
13
|
-
const os = require('os');
|
|
14
|
-
const util = require('util');
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Detects and returns the appropriate logger for the environment
|
|
18
|
-
* @param {object} options - cliArgs from worker
|
|
19
|
-
* @returns {WorkerLogger}
|
|
20
|
-
*/
|
|
21
|
-
function getLogger(options)
|
|
22
|
-
{
|
|
23
|
-
if (options.outputMode === 'detect')
|
|
24
|
-
{
|
|
25
|
-
options.outputMode = 'console';
|
|
26
|
-
/* have TTY - use dashboard when charset supports line drawing */
|
|
27
|
-
if ((process.env.LANG && process.env.LANG.match(/utf-|latin-|iso-8859-/i)) || os.platform() === 'win32')
|
|
28
|
-
options.outputMode = 'dashboard';
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
try
|
|
32
|
-
{
|
|
33
|
-
const om = require('path').basename(options.outputMode);
|
|
34
|
-
return require('./worker-loggers/' + om);
|
|
35
|
-
}
|
|
36
|
-
catch (error)
|
|
37
|
-
{
|
|
38
|
-
if (error.code === 'MODULE_NOT_FOUND')
|
|
39
|
-
{
|
|
40
|
-
const errorMessageStart = error.message.replace(/\n.*/g, '');
|
|
41
|
-
error.message = `Unknown outputMode "${options.outputMode} (${errorMessageStart})`;
|
|
42
|
-
}
|
|
43
|
-
throw error;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Start intercepting console.* methods so that log output from the worker goes to the appropriate log
|
|
49
|
-
* target; eg syslog, file, windows event log, etc. Unlike the telnet console log interceptor which is
|
|
50
|
-
* merely a passthrough shim, this is a "dead end" interceptor - we do not pass the log message through
|
|
51
|
-
* to the original console method. This implies, for example, that sending console messages to syslogd
|
|
52
|
-
* quiesces the tty output.
|
|
53
|
-
*
|
|
54
|
-
* @param {object} options - cliArgs from worker
|
|
55
|
-
*/
|
|
56
|
-
exports.init = function startWorkerLogger$$init(options)
|
|
57
|
-
{
|
|
58
|
-
const logger = getLogger(options);
|
|
59
|
-
|
|
60
|
-
logger.init(options);
|
|
61
|
-
|
|
62
|
-
/* The logger module's exports are its API. The following functions are supported, in this order
|
|
63
|
-
* of severity:
|
|
64
|
-
* . debug: debug-level message
|
|
65
|
-
* . info: informational message
|
|
66
|
-
* . log: normal, but significant, condition
|
|
67
|
-
* . warn: warning conditions
|
|
68
|
-
* . error: error conditions
|
|
69
|
-
*
|
|
70
|
-
* Additionally, generic functions may be used when one of the above is not defined:
|
|
71
|
-
* . at: write a log message at a specific log level; the level is the first argument
|
|
72
|
-
* . raw: same as at, but arguments are not formatted
|
|
73
|
-
* . any: write a log message without regard to log level
|
|
74
|
-
*
|
|
75
|
-
* All of these functions, with the exception of raw, receive only string arguments.
|
|
76
|
-
*/
|
|
77
|
-
|
|
78
|
-
for (let level of ['debug', 'error', 'info', 'log', 'warn'])
|
|
79
|
-
{
|
|
80
|
-
if (logger[level])
|
|
81
|
-
console[level] = (...args) => logger[level]( ...format(...args));
|
|
82
|
-
else if (logger.at)
|
|
83
|
-
console[level] = (...args) => logger.at(level, ...format(...args));
|
|
84
|
-
else if (logger.raw)
|
|
85
|
-
console[level] = (...args) => logger.raw(level, ...args);
|
|
86
|
-
else if (logger.any)
|
|
87
|
-
console[level] = (...args) => logger.any(`${level}:`, format(...args));
|
|
88
|
-
else
|
|
89
|
-
{
|
|
90
|
-
require('./remote-console').reintercept();
|
|
91
|
-
throw new Error('logger module missing export for ' + level);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
if (logger.throb)
|
|
96
|
-
console.throb = logger.throb;
|
|
97
|
-
else
|
|
98
|
-
console.throb = function throwFallback(facility, ...args) {
|
|
99
|
-
if (facility && facility !== 'throb')
|
|
100
|
-
console[facility](...args);
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
require('./remote-console').reintercept();
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Format console.log arguments for use by a non-native logger, eg syslog. All non-string arguments are
|
|
108
|
-
* converted into the best human-readable strings we can muster.
|
|
109
|
-
*/
|
|
110
|
-
function format(...argv)
|
|
111
|
-
{
|
|
112
|
-
for (let i in argv)
|
|
113
|
-
{
|
|
114
|
-
try
|
|
115
|
-
{
|
|
116
|
-
if (typeof argv[i] === 'object' && argv[i] instanceof String)
|
|
117
|
-
argv[i] = String(argv[i]);
|
|
118
|
-
if (typeof argv[i] === 'object')
|
|
119
|
-
argv[i] = util.inspect(argv[i], exports.inspectOptions);
|
|
120
|
-
if (typeof argv[i] !== 'string')
|
|
121
|
-
argv[i] = String(argv[i]);
|
|
122
|
-
}
|
|
123
|
-
catch(e)
|
|
124
|
-
{
|
|
125
|
-
if (e instanceof TypeError)
|
|
126
|
-
argv[i] = '[encoding error: ' + e.message + ']';
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
return argv;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* Options for util.inspect. Loggers which cannot deal with colours should force this false.
|
|
135
|
-
*/
|
|
136
|
-
exports.inspectOptions = {
|
|
137
|
-
colors: process.stdout.isTTY && process.stdout.hasColors() || process.env.FORCE_COLOR,
|
|
138
|
-
};
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file worker-loggers/console.js
|
|
3
|
-
* Logger interface which just logs to the node console on stdout/stderr.
|
|
4
|
-
* @author Wes Garland, wes@distributive.network
|
|
5
|
-
* @date June 2023
|
|
6
|
-
*/
|
|
7
|
-
'use strict';
|
|
8
|
-
|
|
9
|
-
const process = require('process');
|
|
10
|
-
const usingDebugger = require('module')._cache.niim instanceof require('module').Module;
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Initialize the console logger
|
|
14
|
-
*
|
|
15
|
-
* @param {object} options Any options affecting console behaviour. Not presently used.
|
|
16
|
-
*/
|
|
17
|
-
exports.init = function console$$init(options)
|
|
18
|
-
{
|
|
19
|
-
const myConsole = new (require('console').Console)(process);
|
|
20
|
-
var lastWasThrobber = false;
|
|
21
|
-
var i = 0;
|
|
22
|
-
var throbArgsCache = false;
|
|
23
|
-
|
|
24
|
-
delete exports.init; // singleton
|
|
25
|
-
if (process.env.RAW_CONSOLE)
|
|
26
|
-
{
|
|
27
|
-
/* raw mode is used to debug node-inspect problems by dumping raw types directly to console.log */
|
|
28
|
-
exports.raw = function console$$raw(level, ...args) {
|
|
29
|
-
myConsole[level](...args);
|
|
30
|
-
};
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/* Log a single string to the console; conceptually very similar to other loggers */
|
|
35
|
-
exports.at = function console$$at(level, ...args) {
|
|
36
|
-
if (lastWasThrobber)
|
|
37
|
-
{
|
|
38
|
-
args.unshift(' \n');
|
|
39
|
-
lastWasThrobber = false;
|
|
40
|
-
}
|
|
41
|
-
myConsole[level](args.join(' '));
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
const throbChars = '/-\\|';
|
|
45
|
-
/**
|
|
46
|
-
* throb API: calls with arguments set facility and message. First call without argument emits the
|
|
47
|
-
* message. All calls without arguments advance the throbber.
|
|
48
|
-
*/
|
|
49
|
-
exports.throb = function throb(throbFacility, ...args) {
|
|
50
|
-
if (throbFacility)
|
|
51
|
-
{
|
|
52
|
-
throbArgsCache = { throbFacility, args };
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const stream = throbFacility === 'error' || throbFacility === 'warn' ? process.stderr : process.stdout;
|
|
57
|
-
|
|
58
|
-
if (throbArgsCache)
|
|
59
|
-
{
|
|
60
|
-
if (stream.isTTY && !usingDebugger)
|
|
61
|
-
stream.write(throbArgsCache.args.join(' '));
|
|
62
|
-
else
|
|
63
|
-
console[throbArgsCache.throbFacility](...throbArgsCache.args);
|
|
64
|
-
throbArgsCache = false;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (stream.isTTY && !usingDebugger)
|
|
68
|
-
{
|
|
69
|
-
i = (i + 1) % throbChars.length;
|
|
70
|
-
stream.write(throbChars[i] + '\u0008');
|
|
71
|
-
lastWasThrobber = true;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file worker-loggers/dashboard.js
|
|
3
|
-
* @author Ryan Rossiter, ryan@kingsds.network
|
|
4
|
-
* @date April 2020
|
|
5
|
-
*
|
|
6
|
-
* This worker logger uses the blessed library to create
|
|
7
|
-
* a monitoring dashboard for the worker.
|
|
8
|
-
*/
|
|
9
|
-
'use strict';
|
|
10
|
-
|
|
11
|
-
const chalk = require('chalk');
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Initialize the Blessed dashboard
|
|
15
|
-
*
|
|
16
|
-
* @param {object} options Options affecting dasboard behaviour
|
|
17
|
-
*/
|
|
18
|
-
exports.init = function dashboardLogger$$init(options)
|
|
19
|
-
{
|
|
20
|
-
const dashboardTui = require('../dashboard-tui');
|
|
21
|
-
const inspect = Symbol.for('nodejs.util.inspect.custom');
|
|
22
|
-
var throbPos = 0;
|
|
23
|
-
var throbArgsCache = false;
|
|
24
|
-
|
|
25
|
-
function logWrapperFactory(logLevel)
|
|
26
|
-
{
|
|
27
|
-
return function wrappedLogFun() {
|
|
28
|
-
if (!dashboardTui.logPane) /* no logPane => TUI not ready - fallback to console */
|
|
29
|
-
{
|
|
30
|
-
const consoleLogger = require('./console');
|
|
31
|
-
if (consoleLogger.init)
|
|
32
|
-
consoleLogger.init();
|
|
33
|
-
|
|
34
|
-
const logAt = consoleLogger.at || consoleLogger.raw;
|
|
35
|
-
logAt(logLevel, ...arguments);
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const argv = Array.from(arguments);
|
|
40
|
-
for (let i in argv)
|
|
41
|
-
{
|
|
42
|
-
if (argv[i] instanceof Error || (typeof argv[i] === 'object' && argv[i][inspect]))
|
|
43
|
-
argv[i] = require('node:util').inspect(argv[i]);
|
|
44
|
-
else if (logLevel === 'error' && typeof argv[i] === 'string')
|
|
45
|
-
argv[i] = chalk.red(argv[i]);
|
|
46
|
-
}
|
|
47
|
-
dashboardTui.logPane.log(...argv);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
for (let level of ['log', 'warn', 'debug', 'info', 'error'])
|
|
52
|
-
exports[level] = logWrapperFactory(level);
|
|
53
|
-
|
|
54
|
-
const throbChars = '/-\\|';
|
|
55
|
-
/**
|
|
56
|
-
* throb API: calls with arguments set facility and message. First call without argument emits the
|
|
57
|
-
* message. All calls without arguments advance the throbber.
|
|
58
|
-
*/
|
|
59
|
-
exports.throb = function throb(throbFacility, ...args) {
|
|
60
|
-
if (throbFacility)
|
|
61
|
-
{
|
|
62
|
-
throbArgsCache = { throbFacility, args };
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
if (throbArgsCache)
|
|
67
|
-
{
|
|
68
|
-
exports[throbArgsCache.throbFacility](...throbArgsCache.args);
|
|
69
|
-
throbArgsCache = false;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
throbPos = (throbPos + 1) % throbChars.length;
|
|
73
|
-
if (dashboardTui.logPane?.advanceThrob)
|
|
74
|
-
dashboardTui.logPane.advanceThrob(throbChars[throbPos]);
|
|
75
|
-
}
|
|
76
|
-
}
|