dcp-worker 3.2.30-10 → 3.2.30-12
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/bin/dcp-worker +21 -26
- package/etc/dcp-worker-config.js +1 -1
- package/etc/dcp-worker-config.js.md5 +1 -1
- package/lib/blessed-components/sandboxes.js +10 -6
- package/lib/dashboard-tui.js +79 -32
- package/lib/default-ui-events.js +28 -44
- package/lib/startWorkerLogger.js +5 -2
- package/lib/utils.js +28 -0
- package/lib/worker-loggers/dashboard.js +1 -0
- package/package.json +12 -4
package/bin/dcp-worker
CHANGED
|
@@ -4,7 +4,12 @@
|
|
|
4
4
|
* Standalone NodeJS DCP Worker
|
|
5
5
|
*
|
|
6
6
|
* @author Ryan Rossiter, ryan@kingsds.network
|
|
7
|
+
* Paul, paul@distributive.network
|
|
8
|
+
* Wes Garland, wes@distributive.network
|
|
9
|
+
*
|
|
7
10
|
* @date April 2020
|
|
11
|
+
* April-May 2023
|
|
12
|
+
* May-June 2023
|
|
8
13
|
*/
|
|
9
14
|
'use strict';
|
|
10
15
|
|
|
@@ -16,6 +21,7 @@ const path = require('path');
|
|
|
16
21
|
const crypto = require('crypto');
|
|
17
22
|
const chalk = require('chalk');
|
|
18
23
|
const telnetd = require('../lib/remote-console');
|
|
24
|
+
const utils = require('../lib/utils');
|
|
19
25
|
|
|
20
26
|
const configName = process.env.DCP_CONFIG || '../etc/dcp-worker-config';
|
|
21
27
|
const EXIT_UNHANDLED = 5;
|
|
@@ -35,7 +41,9 @@ const replHelpers = {
|
|
|
35
41
|
};
|
|
36
42
|
telnetd.init(replHelpers);
|
|
37
43
|
|
|
38
|
-
/* Initialize dcp-client with local config defaults and run the main function. DCP_CONFIG_COOKIE becomes dcpConfig.cookie.
|
|
44
|
+
/* Initialize dcp-client with local config defaults and run the main function. DCP_CONFIG_COOKIE becomes dcpConfig.cookie.
|
|
45
|
+
* And dcpConfig is defined as a side effect of initializing dcp-client.
|
|
46
|
+
*/
|
|
39
47
|
process.env.DCP_CONFIG_COOKIE = (Math.random().toString(16)).slice(2) + '-' + process.pid + '-' + Date.now();
|
|
40
48
|
require('dcp-client').init({ configName }).then(main).catch(handleUnhandled);
|
|
41
49
|
|
|
@@ -61,7 +69,6 @@ function parseCliArgs()
|
|
|
61
69
|
alias: 'd',
|
|
62
70
|
describe: 'default proportion of CPU,GPU to use when cores not specified',
|
|
63
71
|
type: 'string',
|
|
64
|
-
default: JSON.stringify(dcpConfig.worker.defaultCoreDensity),
|
|
65
72
|
},
|
|
66
73
|
verbose: {
|
|
67
74
|
alias: 'v',
|
|
@@ -400,23 +407,10 @@ async function main()
|
|
|
400
407
|
|
|
401
408
|
function fetchEventHandler(ev)
|
|
402
409
|
{
|
|
403
|
-
var slicesFetched;
|
|
404
|
-
|
|
405
410
|
if (ev instanceof Error)
|
|
406
|
-
{
|
|
407
411
|
console.error('Error fetching task:', ev);
|
|
408
|
-
return;
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
if (typeof ev === 'number' || typeof ev === 'string') /* <= June 2023 Worker events: remove ~ Sep 2023 /wg */
|
|
412
|
-
slicesFetched = ev;
|
|
413
412
|
else
|
|
414
|
-
|
|
415
|
-
const task = ev;
|
|
416
|
-
slicesFetched = task.slices.length;
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
dcpWorkerOptions.leavePublicGroup = Boolean(slicesFetched > 0);
|
|
413
|
+
dcpWorkerOptions.leavePublicGroup = Boolean(utils.slicesFetched(ev) > 0);
|
|
420
414
|
}
|
|
421
415
|
}
|
|
422
416
|
}
|
|
@@ -499,12 +493,13 @@ function processCoresAndDensity (dcpWorkerOptions, cliArgs)
|
|
|
499
493
|
|
|
500
494
|
const parseArg = (which) => {
|
|
501
495
|
if (!cliArgs[which])
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
496
|
+
dcpWorkerOptions[which] = defaultTargets[which];
|
|
497
|
+
else
|
|
498
|
+
{
|
|
499
|
+
const [cpu, gpu] = cliArgs[which].split(',');
|
|
500
|
+
dcpWorkerOptions[which] = { cpu: Number(cpu || defaultTargets[which].cpu),
|
|
501
|
+
gpu: Number(gpu || defaultTargets[which].gpu) };
|
|
502
|
+
}
|
|
508
503
|
};
|
|
509
504
|
|
|
510
505
|
parseArg('density');
|
|
@@ -512,8 +507,8 @@ function processCoresAndDensity (dcpWorkerOptions, cliArgs)
|
|
|
512
507
|
|
|
513
508
|
if (dcpWorkerOptions.cores)
|
|
514
509
|
debugging() && console.debug('dcp-worker: cores =', dcpWorkerOptions.cores);
|
|
515
|
-
|
|
516
|
-
debugging() && console.debug('dcp-worker: core density =', dcpWorkerOptions.
|
|
510
|
+
if (dcpWorkerOptions.density)
|
|
511
|
+
debugging() && console.debug('dcp-worker: core density =', dcpWorkerOptions.density);
|
|
517
512
|
}
|
|
518
513
|
|
|
519
514
|
/**
|
|
@@ -637,14 +632,14 @@ function sliceReport()
|
|
|
637
632
|
|
|
638
633
|
report += ('Progress:') + '\n';
|
|
639
634
|
worker.workingSandboxes.forEach(sb => {
|
|
640
|
-
const jobName = sb.job
|
|
635
|
+
const jobName = sb.job?.public?.name || `idek (${sb.jobAddress})`;
|
|
641
636
|
let el = Date.now() - sb.sliceStartTime;
|
|
642
637
|
const t = el < 1000000
|
|
643
638
|
? toInterval(el)
|
|
644
639
|
: 'new';
|
|
645
640
|
|
|
646
641
|
el = sb.progressReports && sb.progressReports.last
|
|
647
|
-
? Date.now() - (sb.sliceStartTime + sb.progressReports.last
|
|
642
|
+
? Date.now() - (sb.sliceStartTime + (sb.progressReports.last?.timestamp ?? 0))
|
|
648
643
|
: 0;
|
|
649
644
|
const pct = (typeof sb.progress) === 'number'
|
|
650
645
|
? `${Number(sb.progress).toFixed(0).padStart(2)}%`
|
package/etc/dcp-worker-config.js
CHANGED
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
// keystore('~/.dcp/scott'),
|
|
50
50
|
],
|
|
51
51
|
|
|
52
|
-
jobAddresses:
|
|
52
|
+
jobAddresses: false, /* If specified, restrict the worker to only these jobs */
|
|
53
53
|
paymentAddress: undefined, /* Bank account where earned funds are transfered if not specified on command-line */
|
|
54
54
|
},
|
|
55
55
|
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
4d49057dd014344e4be5a266e9754824
|
|
2
2
|
### DO NOT MODIFY THIS FILE!!! ###
|
|
@@ -67,11 +67,7 @@ class Sandboxes extends Box {
|
|
|
67
67
|
update(data=this.data) {
|
|
68
68
|
this.data = data;
|
|
69
69
|
for (let i = 0; i < this.data.length; i++) {
|
|
70
|
-
|
|
71
|
-
this.updateProgressBar(i, this.data[i]);
|
|
72
|
-
} else {
|
|
73
|
-
this.createProgressBar();
|
|
74
|
-
}
|
|
70
|
+
this.updateProgressBar(i, this.data[i]);
|
|
75
71
|
}
|
|
76
72
|
|
|
77
73
|
if (this.data.length < this.progressBars.length) {
|
|
@@ -80,7 +76,15 @@ class Sandboxes extends Box {
|
|
|
80
76
|
}
|
|
81
77
|
}
|
|
82
78
|
|
|
83
|
-
this.setLabel(`${this.options.label} (${this.
|
|
79
|
+
this.setLabel(`${this.options.label} (${this.progressBars.length})`);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Deletes last progress bar
|
|
83
|
+
deleteProgressBar() {
|
|
84
|
+
let i = this.progressBars.length - 1;
|
|
85
|
+
this.progressBars[i].label.destroy()
|
|
86
|
+
this.progressBars[i].progressBar.destroy()
|
|
87
|
+
this.progressBars.pop(i)
|
|
84
88
|
}
|
|
85
89
|
}
|
|
86
90
|
|
package/lib/dashboard-tui.js
CHANGED
|
@@ -15,6 +15,7 @@ const chalk = require('chalk');
|
|
|
15
15
|
const blessed = require('blessed');
|
|
16
16
|
const contrib = require('blessed-contrib');
|
|
17
17
|
const components = require('./blessed-components');
|
|
18
|
+
const utils = require('../lib/utils');
|
|
18
19
|
|
|
19
20
|
const { replaceWorkerEvent, replaceSandboxEvent } = require('./default-ui-events');
|
|
20
21
|
|
|
@@ -52,7 +53,7 @@ exports.init = function dashboard$$init(worker, options)
|
|
|
52
53
|
|
|
53
54
|
const sandboxPane = grid.set(0, 0, 2, 2, components.sandboxes, {
|
|
54
55
|
label: 'Sandboxes',
|
|
55
|
-
defaultProgressBars:
|
|
56
|
+
defaultProgressBars: 0,
|
|
56
57
|
scrollable: true,
|
|
57
58
|
alwaysScroll: true,
|
|
58
59
|
mouse: true,
|
|
@@ -61,6 +62,47 @@ exports.init = function dashboard$$init(worker, options)
|
|
|
61
62
|
},
|
|
62
63
|
});
|
|
63
64
|
|
|
65
|
+
const passwordBox = blessed.textbox({
|
|
66
|
+
parent: screen,
|
|
67
|
+
border: 'line',
|
|
68
|
+
top: 'center',
|
|
69
|
+
left: 'center',
|
|
70
|
+
width: '50%',
|
|
71
|
+
height: 'shrink',
|
|
72
|
+
padding: {
|
|
73
|
+
top: 1
|
|
74
|
+
},
|
|
75
|
+
censor: true,
|
|
76
|
+
inputOnFocus: true,
|
|
77
|
+
label: 'Password Prompt:',
|
|
78
|
+
hidden: true,
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
function askPassword(promptMessage)
|
|
82
|
+
{
|
|
83
|
+
return new Promise((resolve, reject) => {
|
|
84
|
+
passwordBox.focus();
|
|
85
|
+
passwordBox.show();
|
|
86
|
+
passwordBox.setLabel(promptMessage);
|
|
87
|
+
|
|
88
|
+
function passwordSubmitFn(value)
|
|
89
|
+
{
|
|
90
|
+
passwordBox.hide();
|
|
91
|
+
passwordBox.removeListener('submit', passwordSubmitFn);
|
|
92
|
+
passwordBox.setValue('');
|
|
93
|
+
resolve(value);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
passwordBox.on('submit', passwordSubmitFn);
|
|
97
|
+
screen.render();
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// override wallet.passphrasePrompt with password box
|
|
102
|
+
require('dcp/wallet').passphrasePrompt = (promptMessage) => {
|
|
103
|
+
return askPassword(promptMessage);
|
|
104
|
+
};
|
|
105
|
+
|
|
64
106
|
delete exports.init; /* singleton */
|
|
65
107
|
|
|
66
108
|
if (!usingDebugger)
|
|
@@ -99,23 +141,27 @@ exports.init = function dashboard$$init(worker, options)
|
|
|
99
141
|
|
|
100
142
|
/* Override default event behaviour to work better with the Dashboard. */
|
|
101
143
|
|
|
102
|
-
|
|
144
|
+
/** XXXpfr @todo Is this correct? Or should we init progressData inside 'slice' like we used to. */
|
|
145
|
+
replaceSandboxEvent('ready', function dashboard$$job(sandbox, sandboxData, ev) {
|
|
103
146
|
sandboxData.progressData = {
|
|
104
147
|
indeterminate: true,
|
|
105
148
|
progress: 0,
|
|
106
|
-
label: sandbox.public.name,
|
|
149
|
+
label: sandbox?.public ? sandbox.public.name: '<no-label>',
|
|
107
150
|
};
|
|
108
|
-
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
replaceSandboxEvent('slice', function dashboard$$slice(sandbox, sandboxData, ev) {
|
|
109
154
|
sandboxPane.data.push(sandboxData.progressData);
|
|
110
155
|
sandboxPane.update();
|
|
111
156
|
});
|
|
112
157
|
|
|
113
|
-
replaceSandboxEvent('
|
|
114
|
-
if (ev
|
|
158
|
+
replaceSandboxEvent('progress', function dashboard$$progress(sandbox, sandboxData, ev) {
|
|
159
|
+
if (!ev)
|
|
115
160
|
{
|
|
116
161
|
sandboxData.progressData.progress = 100;
|
|
117
162
|
setTimeout(() => {
|
|
118
|
-
if (sandboxData.progressData.indeterminate)
|
|
163
|
+
if (sandboxData.progressData.indeterminate)
|
|
164
|
+
{
|
|
119
165
|
sandboxData.progressData.progress = 0;
|
|
120
166
|
sandboxPane.update();
|
|
121
167
|
}
|
|
@@ -123,53 +169,54 @@ exports.init = function dashboard$$init(worker, options)
|
|
|
123
169
|
}
|
|
124
170
|
else
|
|
125
171
|
{
|
|
126
|
-
sandboxData.progressData.progress = ev
|
|
172
|
+
sandboxData.progressData.progress = ev;
|
|
127
173
|
sandboxData.progressData.indeterminate = false;
|
|
128
174
|
}
|
|
129
175
|
|
|
130
176
|
sandboxPane.update();
|
|
131
177
|
});
|
|
132
178
|
|
|
133
|
-
replaceSandboxEvent('
|
|
179
|
+
replaceSandboxEvent('sliceEnd', function dashboard$$sliceEnd(sandbox, sandboxData, ev) {
|
|
134
180
|
sandboxPane.data = sandboxPane.data.filter(d => d != sandboxData.progressData);
|
|
181
|
+
sandboxData.progressData.progress = 0;
|
|
135
182
|
sandboxPane.update();
|
|
136
183
|
});
|
|
137
184
|
|
|
138
|
-
|
|
185
|
+
replaceSandboxEvent('end', function dashboard$$end(sandbox, sandboxData, ev) {
|
|
186
|
+
sandboxPane.data = sandboxPane.data.filter(d => d != sandboxData.progressData);
|
|
187
|
+
sandboxPane.deleteProgressBar();
|
|
188
|
+
sandboxData.progressData.progress = 0;
|
|
189
|
+
sandboxPane.update();
|
|
190
|
+
});
|
|
139
191
|
|
|
140
|
-
replaceWorkerEvent('
|
|
192
|
+
replaceWorkerEvent('beforeFetch', function dashboard$$beforeFetch(ev) {
|
|
141
193
|
sliceFetchStatus = SLICE_FETCH_STATUS.FETCHING;
|
|
142
194
|
updateWorkerInfo();
|
|
143
195
|
});
|
|
144
196
|
|
|
145
197
|
replaceWorkerEvent('fetch', function dashboard$$fetch(ev) {
|
|
146
|
-
|
|
147
|
-
|
|
198
|
+
sliceFetchStatus = SLICE_FETCH_STATUS.NO_WORK;
|
|
148
199
|
if (ev instanceof Error)
|
|
149
|
-
{
|
|
150
200
|
console.error('Error fetching slices:', ev);
|
|
151
|
-
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
if (typeof ev === 'number' || typeof ev === 'string') /* <= June 2023 Worker events: remove ~ Sep 2023 /wg */
|
|
155
|
-
slicesFetched = ev;
|
|
156
|
-
else
|
|
157
|
-
{
|
|
158
|
-
const task = ev;
|
|
159
|
-
slicesFetched = task.slices.length;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
if (slicesFetched === 0 && sandboxPane.data.length === 0) {
|
|
163
|
-
sliceFetchStatus = SLICE_FETCH_STATUS.NO_WORK;
|
|
164
|
-
} else {
|
|
201
|
+
else if ( !(utils.slicesFetched(ev) === 0 && sandboxPane.data.length === 0))
|
|
165
202
|
sliceFetchStatus = SLICE_FETCH_STATUS.WORKING;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
203
|
updateWorkerInfo();
|
|
169
204
|
});
|
|
170
205
|
|
|
171
|
-
|
|
172
|
-
|
|
206
|
+
worker.on('end', () => { screen.destroy(); });
|
|
207
|
+
|
|
208
|
+
worker.on('sandbox', function dashboard$$sandbox(ev) {
|
|
209
|
+
sandboxPane.createProgressBar();
|
|
210
|
+
sandboxPane.update();
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
worker.on('payment', function dashboard$$payment(ev) {
|
|
214
|
+
const payment = parseFloat(ev);
|
|
215
|
+
|
|
216
|
+
if (!isNaN(payment))
|
|
217
|
+
totalDCCs += payment;
|
|
218
|
+
|
|
219
|
+
sandboxPane.update();
|
|
173
220
|
updateWorkerInfo();
|
|
174
221
|
});
|
|
175
222
|
};
|
package/lib/default-ui-events.js
CHANGED
|
@@ -26,6 +26,8 @@
|
|
|
26
26
|
*/
|
|
27
27
|
'use strict';
|
|
28
28
|
|
|
29
|
+
const utils = require('../lib/utils');
|
|
30
|
+
|
|
29
31
|
const sandboxEventHandlers = {};
|
|
30
32
|
const workerEventHandlers = {};
|
|
31
33
|
|
|
@@ -50,35 +52,28 @@ exports.hook = function hookWorkerEvents$$hook(worker, options)
|
|
|
50
52
|
if (!sandbox.jobAddress)
|
|
51
53
|
return '<no job>';
|
|
52
54
|
|
|
53
|
-
const address = sandbox.jobAddress
|
|
54
|
-
const baseInfo = sandbox
|
|
55
|
+
const address = sandbox.jobAddress.slice(0, truncationLength);
|
|
56
|
+
const baseInfo = sandbox?.public ? `${address}: ${sandbox.public.name}` : address;
|
|
55
57
|
|
|
56
58
|
if (!sliceNumber)
|
|
57
|
-
sliceNumber = sandbox.
|
|
58
|
-
return sliceNumber ? `slice ${sliceNumber}, ${baseInfo}` : baseInfo;
|
|
59
|
+
sliceNumber = sandbox.sliceNumber;
|
|
60
|
+
return sliceNumber > 0 ? `slice ${sliceNumber}, ${baseInfo}` : baseInfo;
|
|
59
61
|
}
|
|
60
62
|
|
|
61
63
|
sandboxEventHandlers.ready = function sandboxReadyHandler(sandbox, sandboxData, ev) {
|
|
62
64
|
console.log(` . Sandbox ${sandboxData.shortId}: Initialized`);
|
|
63
65
|
};
|
|
64
66
|
|
|
65
|
-
sandboxEventHandlers.
|
|
66
|
-
|
|
67
|
-
console.log(` * Sandbox ${sandboxData.shortId}: Terminated: ${makeSliceId(sandbox, sliceInfo?.slice)}`);
|
|
68
|
-
delete sliceMap[sandbox.id];
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
sandboxEventHandlers.start = function sliceStartHandler(sandbox, sandboxData, ev) {
|
|
72
|
-
const sliceNumber = sandbox.slice ? sandbox.slice.sliceNumber : 0;
|
|
73
|
-
sliceMap[sandbox.id] = { slice: sliceNumber, t0: Date.now() };
|
|
67
|
+
sandboxEventHandlers.slice = function sliceHandler(sandbox, sandboxData, ev) {
|
|
68
|
+
sliceMap[sandbox.id] = { slice: sandbox.sliceNumber, t0: Date.now() };
|
|
74
69
|
console.log(` . Sandbox ${sandboxData.shortId}: Slice Started: ${makeSliceId(sandbox)}`);
|
|
75
70
|
};
|
|
76
71
|
|
|
77
|
-
sandboxEventHandlers.
|
|
78
|
-
//
|
|
72
|
+
sandboxEventHandlers.progress = function progressHandler(sandbox, sandboxdData, ev) {
|
|
73
|
+
// Overridden in dashboard-tui.js
|
|
79
74
|
};
|
|
80
75
|
|
|
81
|
-
sandboxEventHandlers.
|
|
76
|
+
sandboxEventHandlers.sliceEnd = function sliceEndHandler(sandbox, sandboxData, ev) {
|
|
82
77
|
const sliceInfo = sliceMap[sandbox.id];
|
|
83
78
|
if (sliceInfo)
|
|
84
79
|
console.log(` * Sandbox ${sandboxData.shortId}: Slice Completed: ${makeSliceId(sandbox, sliceInfo.slice)}: dt ${Date.now() - sliceInfo.t0}ms`);
|
|
@@ -86,8 +81,14 @@ exports.hook = function hookWorkerEvents$$hook(worker, options)
|
|
|
86
81
|
console.log(` * Sandbox ${sandboxData.shortId}: Slice Completed: ${makeSliceId(sandbox)}`);
|
|
87
82
|
};
|
|
88
83
|
|
|
84
|
+
sandboxEventHandlers.end = function endHandler(sandbox,sandboxData, ev) {
|
|
85
|
+
const sliceInfo = sliceMap[sandbox.id];
|
|
86
|
+
console.log(` * Sandbox ${sandboxData.shortId}: Terminated: ${makeSliceId(sandbox, sliceInfo?.slice)}`);
|
|
87
|
+
delete sliceMap[sandbox.id];
|
|
88
|
+
};
|
|
89
|
+
|
|
89
90
|
workerEventHandlers.payment = function paymentHandler(ev) {
|
|
90
|
-
const payment = parseFloat(ev
|
|
91
|
+
const payment = parseFloat(ev);
|
|
91
92
|
|
|
92
93
|
if (isNaN(payment))
|
|
93
94
|
console.error(' ! Failed to parse payment:', payment);
|
|
@@ -95,44 +96,27 @@ exports.hook = function hookWorkerEvents$$hook(worker, options)
|
|
|
95
96
|
console.log(` . Payment: ${payment.toFixed(3)} ⊇`);
|
|
96
97
|
};
|
|
97
98
|
|
|
98
|
-
workerEventHandlers.
|
|
99
|
+
workerEventHandlers.beforeFetch = function beforeFetchHandler() {
|
|
99
100
|
options.verbose && console.log(' * Fetching slices...');
|
|
100
101
|
};
|
|
101
102
|
|
|
102
103
|
workerEventHandlers.fetch = function fetchHandler(ev) {
|
|
103
|
-
var slicesFetched;
|
|
104
|
-
|
|
105
104
|
if (ev instanceof Error)
|
|
106
|
-
{
|
|
107
105
|
console.error(' ! Failed to fetch slices:', ev);
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
if (typeof ev === 'number' || typeof ev === 'string') /* <= June 2023 Worker events: remove ~ Sep 2023 /wg */
|
|
112
|
-
slicesFetched = ev;
|
|
113
106
|
else
|
|
114
|
-
|
|
115
|
-
const task = ev;
|
|
116
|
-
slicesFetched = task.slices.length;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
options.verbose && console.log(' . Fetched', slicesFetched, 'slices');
|
|
107
|
+
options.verbose && console.log(' . Fetched', utils.slicesFetched(ev), 'slices');
|
|
120
108
|
};
|
|
121
109
|
|
|
122
|
-
workerEventHandlers.fetchError = function fetchErrorHandler(ev) {
|
|
123
|
-
console.log(' ! Failed to fetch slices:', ev);
|
|
124
|
-
};
|
|
125
110
|
|
|
126
|
-
workerEventHandlers.
|
|
111
|
+
workerEventHandlers.beforeResult = function beforeResultHandler() {
|
|
127
112
|
options.verbose >= 2 && console.log(' * Submitting results...');
|
|
128
113
|
};
|
|
129
114
|
|
|
130
|
-
workerEventHandlers.
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
console.log(' ! Failed to submit results:', ev);
|
|
115
|
+
workerEventHandlers.result = function resultHandler(ev) {
|
|
116
|
+
if (ev instanceof Error)
|
|
117
|
+
console.error(" ! Failed to submit results:", ev);
|
|
118
|
+
else
|
|
119
|
+
options.verbose >= 2 && console.log(' . Submitted');
|
|
136
120
|
};
|
|
137
121
|
|
|
138
122
|
/* Register the appropriate event handlers on the worker and on each sandbox. The handlers are
|
|
@@ -144,14 +128,14 @@ exports.hook = function hookWorkerEvents$$hook(worker, options)
|
|
|
144
128
|
* called `sandboxData` which is just arbitrary storage for the eventHandlers' use, eg for memos.
|
|
145
129
|
*/
|
|
146
130
|
for (let eventName in workerEventHandlers)
|
|
147
|
-
worker.
|
|
131
|
+
worker.on(eventName, (...args) => workerEventHandlers[eventName](...args));
|
|
148
132
|
|
|
149
133
|
worker.on('sandbox', function newSandboxHandler(sandbox) {
|
|
150
134
|
const sandboxData = {
|
|
151
135
|
shortId: sandbox.id.toString(10).padStart(3)
|
|
152
136
|
};
|
|
153
137
|
for (let eventName in sandboxEventHandlers)
|
|
154
|
-
sandbox.
|
|
138
|
+
sandbox.on(eventName, (...args) => sandboxEventHandlers[eventName](sandbox, sandboxData, ...args));
|
|
155
139
|
});
|
|
156
140
|
|
|
157
141
|
exports.sandboxEventHandlers = sandboxEventHandlers;
|
package/lib/startWorkerLogger.js
CHANGED
|
@@ -36,7 +36,10 @@ function getLogger(options)
|
|
|
36
36
|
catch (error)
|
|
37
37
|
{
|
|
38
38
|
if (error.code === 'MODULE_NOT_FOUND')
|
|
39
|
-
|
|
39
|
+
{
|
|
40
|
+
const errorMessageStart = error.message.replace(/\n.*/g, '');
|
|
41
|
+
error.message = `Unknown outputMode "${options.outputMode} (${errorMessageStart})`;
|
|
42
|
+
}
|
|
40
43
|
throw error;
|
|
41
44
|
}
|
|
42
45
|
}
|
|
@@ -123,5 +126,5 @@ function format(...argv)
|
|
|
123
126
|
* Options for util.inspect. Loggers which cannot deal with colours should force this false.
|
|
124
127
|
*/
|
|
125
128
|
exports.inspectOptions = {
|
|
126
|
-
colors: process.stdout.hasColors() || process.env.FORCE_COLOR,
|
|
129
|
+
colors: process.stdout.isTTY && process.stdout.hasColors() || process.env.FORCE_COLOR,
|
|
127
130
|
};
|
package/lib/utils.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* @file utils.js
|
|
4
|
+
* Shared library code.
|
|
5
|
+
*
|
|
6
|
+
* @author Paul, paul@distributive.network
|
|
7
|
+
* @date August 2023
|
|
8
|
+
*/
|
|
9
|
+
'use strict';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Figure out #slices fetched from the different forms of the 'fetch' event.
|
|
13
|
+
* @param {*|string|number} task
|
|
14
|
+
* @returns {number}
|
|
15
|
+
*/
|
|
16
|
+
function slicesFetched (task)
|
|
17
|
+
{
|
|
18
|
+
if (typeof task === 'number') /* <= June 2023 Worker events: remove ~ Sep 2023 /wg */
|
|
19
|
+
return task;
|
|
20
|
+
if (typeof task === 'string') /* <= June 2023 Worker events: remove ~ Sep 2023 /wg */
|
|
21
|
+
return parseInt(task) || 0;
|
|
22
|
+
let slicesFetched = 0;
|
|
23
|
+
for (const job in task.slices)
|
|
24
|
+
slicesFetched += task.slices[job];
|
|
25
|
+
return slicesFetched;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
exports.slicesFetched = slicesFetched;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dcp-worker",
|
|
3
|
-
"version": "3.2.30-
|
|
3
|
+
"version": "3.2.30-12",
|
|
4
4
|
"description": "JavaScript portion of DCP Workers for Node.js",
|
|
5
5
|
"main": "bin/dcp-worker",
|
|
6
6
|
"keywords": [
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"blessed": "^0.1.81",
|
|
38
38
|
"blessed-contrib": "^4.11.0",
|
|
39
39
|
"chalk": "^4.1.0",
|
|
40
|
-
"dcp-client": "4.3.0-
|
|
40
|
+
"dcp-client": "4.3.0-5",
|
|
41
41
|
"semver": "^7.3.8",
|
|
42
42
|
"syslog-client": "1.1.1"
|
|
43
43
|
},
|
|
@@ -46,10 +46,18 @@
|
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@kingsds/eslint-config": "^1.0.1",
|
|
49
|
-
"eslint": "
|
|
49
|
+
"eslint": ">=8"
|
|
50
|
+
},
|
|
51
|
+
"peerDependencies": {
|
|
52
|
+
"node-eventlog": "https://gitpkg.now.sh/Distributive-Network/node-eventlog/package?dcp/0.0.1"
|
|
53
|
+
},
|
|
54
|
+
"peerDependenciesMeta": {
|
|
55
|
+
"node-eventlog": {
|
|
56
|
+
"optional": true
|
|
57
|
+
}
|
|
50
58
|
},
|
|
51
59
|
"engines": {
|
|
52
|
-
"node": ">=
|
|
60
|
+
"node": ">=18",
|
|
53
61
|
"npm": ">=7"
|
|
54
62
|
}
|
|
55
63
|
}
|