dcp-worker 3.2.30-5 → 3.2.30-7
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 +26 -21
- package/etc/dcp-worker-config.js +1 -1
- package/etc/dcp-worker-config.js.md5 +1 -1
- package/lib/blessed-components/sandboxes.js +6 -10
- package/lib/dashboard-tui.js +32 -79
- package/lib/default-ui-events.js +44 -28
- package/lib/startWorkerLogger.js +2 -5
- package/lib/worker-loggers/dashboard.js +0 -1
- package/package.json +3 -11
- package/lib/utils.js +0 -28
package/bin/dcp-worker
CHANGED
|
@@ -4,12 +4,7 @@
|
|
|
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
|
-
*
|
|
10
7
|
* @date April 2020
|
|
11
|
-
* April-May 2023
|
|
12
|
-
* May-June 2023
|
|
13
8
|
*/
|
|
14
9
|
'use strict';
|
|
15
10
|
|
|
@@ -21,7 +16,6 @@ const path = require('path');
|
|
|
21
16
|
const crypto = require('crypto');
|
|
22
17
|
const chalk = require('chalk');
|
|
23
18
|
const telnetd = require('../lib/remote-console');
|
|
24
|
-
const utils = require('../lib/utils');
|
|
25
19
|
|
|
26
20
|
const configName = process.env.DCP_CONFIG || '../etc/dcp-worker-config';
|
|
27
21
|
const EXIT_UNHANDLED = 5;
|
|
@@ -41,9 +35,7 @@ const replHelpers = {
|
|
|
41
35
|
};
|
|
42
36
|
telnetd.init(replHelpers);
|
|
43
37
|
|
|
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
|
-
*/
|
|
38
|
+
/* Initialize dcp-client with local config defaults and run the main function. DCP_CONFIG_COOKIE becomes dcpConfig.cookie. */
|
|
47
39
|
process.env.DCP_CONFIG_COOKIE = (Math.random().toString(16)).slice(2) + '-' + process.pid + '-' + Date.now();
|
|
48
40
|
require('dcp-client').init({ configName }).then(main).catch(handleUnhandled);
|
|
49
41
|
|
|
@@ -69,6 +61,7 @@ function parseCliArgs()
|
|
|
69
61
|
alias: 'd',
|
|
70
62
|
describe: 'default proportion of CPU,GPU to use when cores not specified',
|
|
71
63
|
type: 'string',
|
|
64
|
+
default: JSON.stringify(dcpConfig.worker.defaultCoreDensity),
|
|
72
65
|
},
|
|
73
66
|
verbose: {
|
|
74
67
|
alias: 'v',
|
|
@@ -407,10 +400,23 @@ async function main()
|
|
|
407
400
|
|
|
408
401
|
function fetchEventHandler(ev)
|
|
409
402
|
{
|
|
403
|
+
var slicesFetched;
|
|
404
|
+
|
|
410
405
|
if (ev instanceof Error)
|
|
406
|
+
{
|
|
411
407
|
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;
|
|
412
413
|
else
|
|
413
|
-
|
|
414
|
+
{
|
|
415
|
+
const task = ev;
|
|
416
|
+
slicesFetched = task.slices.length;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
dcpWorkerOptions.leavePublicGroup = Boolean(slicesFetched > 0);
|
|
414
420
|
}
|
|
415
421
|
}
|
|
416
422
|
}
|
|
@@ -493,13 +499,12 @@ function processCoresAndDensity (dcpWorkerOptions, cliArgs)
|
|
|
493
499
|
|
|
494
500
|
const parseArg = (which) => {
|
|
495
501
|
if (!cliArgs[which])
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
}
|
|
502
|
+
return false;
|
|
503
|
+
|
|
504
|
+
const [cpu, gpu] = cliArgs[which].split(',');
|
|
505
|
+
dcpWorkerOptions[which] = { cpu: Number(cpu || defaultTargets[which].cpu),
|
|
506
|
+
gpu: Number(gpu || defaultTargets[which].gpu) };
|
|
507
|
+
return true;
|
|
503
508
|
};
|
|
504
509
|
|
|
505
510
|
parseArg('density');
|
|
@@ -507,8 +512,8 @@ function processCoresAndDensity (dcpWorkerOptions, cliArgs)
|
|
|
507
512
|
|
|
508
513
|
if (dcpWorkerOptions.cores)
|
|
509
514
|
debugging() && console.debug('dcp-worker: cores =', dcpWorkerOptions.cores);
|
|
510
|
-
|
|
511
|
-
debugging() && console.debug('dcp-worker: core density =', dcpWorkerOptions.
|
|
515
|
+
else
|
|
516
|
+
debugging() && console.debug('dcp-worker: core density =', dcpWorkerOptions.defaultCoreDensity);
|
|
512
517
|
}
|
|
513
518
|
|
|
514
519
|
/**
|
|
@@ -632,14 +637,14 @@ function sliceReport()
|
|
|
632
637
|
|
|
633
638
|
report += ('Progress:') + '\n';
|
|
634
639
|
worker.workingSandboxes.forEach(sb => {
|
|
635
|
-
const jobName = sb.job
|
|
640
|
+
const jobName = sb.job && sb.job.public && sb.job.public.name || `idek (${sb.jobAddress})`;
|
|
636
641
|
let el = Date.now() - sb.sliceStartTime;
|
|
637
642
|
const t = el < 1000000
|
|
638
643
|
? toInterval(el)
|
|
639
644
|
: 'new';
|
|
640
645
|
|
|
641
646
|
el = sb.progressReports && sb.progressReports.last
|
|
642
|
-
? Date.now() - (sb.sliceStartTime +
|
|
647
|
+
? Date.now() - (sb.sliceStartTime + sb.progressReports.last.timestamp)
|
|
643
648
|
: 0;
|
|
644
649
|
const pct = (typeof sb.progress) === 'number'
|
|
645
650
|
? `${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: [], /* 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
|
+
8edf1c57bee521ed7f151a21b8f3f34d
|
|
2
2
|
### DO NOT MODIFY THIS FILE!!! ###
|
|
@@ -67,7 +67,11 @@ 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
|
-
|
|
70
|
+
if (i < this.progressBars.length) {
|
|
71
|
+
this.updateProgressBar(i, this.data[i]);
|
|
72
|
+
} else {
|
|
73
|
+
this.createProgressBar();
|
|
74
|
+
}
|
|
71
75
|
}
|
|
72
76
|
|
|
73
77
|
if (this.data.length < this.progressBars.length) {
|
|
@@ -76,15 +80,7 @@ class Sandboxes extends Box {
|
|
|
76
80
|
}
|
|
77
81
|
}
|
|
78
82
|
|
|
79
|
-
this.setLabel(`${this.options.label} (${this.
|
|
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)
|
|
83
|
+
this.setLabel(`${this.options.label} (${this.data.length})`);
|
|
88
84
|
}
|
|
89
85
|
}
|
|
90
86
|
|
package/lib/dashboard-tui.js
CHANGED
|
@@ -15,7 +15,6 @@ 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');
|
|
19
18
|
|
|
20
19
|
const { replaceWorkerEvent, replaceSandboxEvent } = require('./default-ui-events');
|
|
21
20
|
|
|
@@ -53,7 +52,7 @@ exports.init = function dashboard$$init(worker, options)
|
|
|
53
52
|
|
|
54
53
|
const sandboxPane = grid.set(0, 0, 2, 2, components.sandboxes, {
|
|
55
54
|
label: 'Sandboxes',
|
|
56
|
-
defaultProgressBars:
|
|
55
|
+
defaultProgressBars: Math.floor(worker.workerOptions.cores.cpu) || 1,
|
|
57
56
|
scrollable: true,
|
|
58
57
|
alwaysScroll: true,
|
|
59
58
|
mouse: true,
|
|
@@ -62,47 +61,6 @@ exports.init = function dashboard$$init(worker, options)
|
|
|
62
61
|
},
|
|
63
62
|
});
|
|
64
63
|
|
|
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
|
-
|
|
106
64
|
delete exports.init; /* singleton */
|
|
107
65
|
|
|
108
66
|
if (!usingDebugger)
|
|
@@ -141,27 +99,23 @@ exports.init = function dashboard$$init(worker, options)
|
|
|
141
99
|
|
|
142
100
|
/* Override default event behaviour to work better with the Dashboard. */
|
|
143
101
|
|
|
144
|
-
|
|
145
|
-
replaceSandboxEvent('ready', function dashboard$$job(sandbox, sandboxData, ev) {
|
|
102
|
+
replaceSandboxEvent('start', function dashboard$$sliceStart(sandbox, sandboxData, ev) {
|
|
146
103
|
sandboxData.progressData = {
|
|
147
104
|
indeterminate: true,
|
|
148
105
|
progress: 0,
|
|
149
|
-
label: sandbox
|
|
106
|
+
label: sandbox.public.name,
|
|
150
107
|
};
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
replaceSandboxEvent('slice', function dashboard$$slice(sandbox, sandboxData, ev) {
|
|
108
|
+
|
|
154
109
|
sandboxPane.data.push(sandboxData.progressData);
|
|
155
110
|
sandboxPane.update();
|
|
156
111
|
});
|
|
157
112
|
|
|
158
|
-
replaceSandboxEvent('
|
|
159
|
-
if (
|
|
113
|
+
replaceSandboxEvent('sliceProgress', function dashboard$$sliceProgress(sandbox, sandboxData, ev) {
|
|
114
|
+
if (ev.indeterminate)
|
|
160
115
|
{
|
|
161
116
|
sandboxData.progressData.progress = 100;
|
|
162
117
|
setTimeout(() => {
|
|
163
|
-
if (sandboxData.progressData.indeterminate)
|
|
164
|
-
{
|
|
118
|
+
if (sandboxData.progressData.indeterminate) {
|
|
165
119
|
sandboxData.progressData.progress = 0;
|
|
166
120
|
sandboxPane.update();
|
|
167
121
|
}
|
|
@@ -169,54 +123,53 @@ exports.init = function dashboard$$init(worker, options)
|
|
|
169
123
|
}
|
|
170
124
|
else
|
|
171
125
|
{
|
|
172
|
-
sandboxData.progressData.progress = ev;
|
|
126
|
+
sandboxData.progressData.progress = ev.progress;
|
|
173
127
|
sandboxData.progressData.indeterminate = false;
|
|
174
128
|
}
|
|
175
129
|
|
|
176
130
|
sandboxPane.update();
|
|
177
131
|
});
|
|
178
132
|
|
|
179
|
-
replaceSandboxEvent('
|
|
133
|
+
replaceSandboxEvent('sliceFinish', function dashboard$$sliceFinish(sandbox, sandboxData, ev) {
|
|
180
134
|
sandboxPane.data = sandboxPane.data.filter(d => d != sandboxData.progressData);
|
|
181
|
-
sandboxData.progressData.progress = 0;
|
|
182
135
|
sandboxPane.update();
|
|
183
136
|
});
|
|
184
137
|
|
|
185
|
-
|
|
186
|
-
sandboxPane.data = sandboxPane.data.filter(d => d != sandboxData.progressData);
|
|
187
|
-
sandboxPane.deleteProgressBar();
|
|
188
|
-
sandboxData.progressData.progress = 0;
|
|
189
|
-
sandboxPane.update();
|
|
190
|
-
});
|
|
138
|
+
worker.on('payment', updateWorkerInfo);
|
|
191
139
|
|
|
192
|
-
replaceWorkerEvent('
|
|
140
|
+
replaceWorkerEvent('fetchStart', function dashboard$$fetchStart(ev) {
|
|
193
141
|
sliceFetchStatus = SLICE_FETCH_STATUS.FETCHING;
|
|
194
142
|
updateWorkerInfo();
|
|
195
143
|
});
|
|
196
144
|
|
|
197
145
|
replaceWorkerEvent('fetch', function dashboard$$fetch(ev) {
|
|
198
|
-
|
|
146
|
+
var slicesFetched;
|
|
147
|
+
|
|
199
148
|
if (ev instanceof Error)
|
|
149
|
+
{
|
|
200
150
|
console.error('Error fetching slices:', ev);
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
updateWorkerInfo();
|
|
204
|
-
});
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
205
153
|
|
|
206
|
-
|
|
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
|
+
}
|
|
207
161
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
162
|
+
if (slicesFetched === 0 && sandboxPane.data.length === 0) {
|
|
163
|
+
sliceFetchStatus = SLICE_FETCH_STATUS.NO_WORK;
|
|
164
|
+
} else {
|
|
165
|
+
sliceFetchStatus = SLICE_FETCH_STATUS.WORKING;
|
|
166
|
+
}
|
|
212
167
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
if (!isNaN(payment))
|
|
217
|
-
totalDCCs += payment;
|
|
168
|
+
updateWorkerInfo();
|
|
169
|
+
});
|
|
218
170
|
|
|
219
|
-
|
|
171
|
+
replaceWorkerEvent('fetchError', function dashabord$$fetchError() {
|
|
172
|
+
sliceFetchStatus = SLICE_FETCH_STATUS.NO_WORK;
|
|
220
173
|
updateWorkerInfo();
|
|
221
174
|
});
|
|
222
175
|
};
|
package/lib/default-ui-events.js
CHANGED
|
@@ -26,8 +26,6 @@
|
|
|
26
26
|
*/
|
|
27
27
|
'use strict';
|
|
28
28
|
|
|
29
|
-
const utils = require('../lib/utils');
|
|
30
|
-
|
|
31
29
|
const sandboxEventHandlers = {};
|
|
32
30
|
const workerEventHandlers = {};
|
|
33
31
|
|
|
@@ -52,28 +50,35 @@ exports.hook = function hookWorkerEvents$$hook(worker, options)
|
|
|
52
50
|
if (!sandbox.jobAddress)
|
|
53
51
|
return '<no job>';
|
|
54
52
|
|
|
55
|
-
const address = sandbox.jobAddress.slice(0, truncationLength);
|
|
56
|
-
const baseInfo = sandbox?.
|
|
53
|
+
const address = sandbox.jobAddress ? sandbox.jobAddress.slice(0, truncationLength) : 'null';
|
|
54
|
+
const baseInfo = sandbox.public?.name ? `${address}: ${sandbox.public.name}` : `${address}:`;
|
|
57
55
|
|
|
58
56
|
if (!sliceNumber)
|
|
59
|
-
sliceNumber = sandbox.sliceNumber;
|
|
60
|
-
return sliceNumber
|
|
57
|
+
sliceNumber = sandbox.slice ? sandbox.slice.sliceNumber : 0;
|
|
58
|
+
return sliceNumber ? `slice ${sliceNumber}, ${baseInfo}` : baseInfo;
|
|
61
59
|
}
|
|
62
60
|
|
|
63
61
|
sandboxEventHandlers.ready = function sandboxReadyHandler(sandbox, sandboxData, ev) {
|
|
64
62
|
console.log(` . Sandbox ${sandboxData.shortId}: Initialized`);
|
|
65
63
|
};
|
|
66
64
|
|
|
67
|
-
sandboxEventHandlers.
|
|
68
|
-
sliceMap[sandbox.id]
|
|
65
|
+
sandboxEventHandlers.terminated = function sandboxTerminatedHandler(sandbox, sandboxData, ev) {
|
|
66
|
+
const sliceInfo = sliceMap[sandbox.id];
|
|
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() };
|
|
69
74
|
console.log(` . Sandbox ${sandboxData.shortId}: Slice Started: ${makeSliceId(sandbox)}`);
|
|
70
75
|
};
|
|
71
76
|
|
|
72
|
-
sandboxEventHandlers.
|
|
73
|
-
//
|
|
77
|
+
sandboxEventHandlers.sliceProgress = function sliceProgressHandler(sandbox, sandbodData, ev) {
|
|
78
|
+
// NOP
|
|
74
79
|
};
|
|
75
80
|
|
|
76
|
-
sandboxEventHandlers.
|
|
81
|
+
sandboxEventHandlers.sliceFinish = function sliceFinishHandler(sandbox, sandboxData, ev) {
|
|
77
82
|
const sliceInfo = sliceMap[sandbox.id];
|
|
78
83
|
if (sliceInfo)
|
|
79
84
|
console.log(` * Sandbox ${sandboxData.shortId}: Slice Completed: ${makeSliceId(sandbox, sliceInfo.slice)}: dt ${Date.now() - sliceInfo.t0}ms`);
|
|
@@ -81,14 +86,8 @@ exports.hook = function hookWorkerEvents$$hook(worker, options)
|
|
|
81
86
|
console.log(` * Sandbox ${sandboxData.shortId}: Slice Completed: ${makeSliceId(sandbox)}`);
|
|
82
87
|
};
|
|
83
88
|
|
|
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
|
-
|
|
90
89
|
workerEventHandlers.payment = function paymentHandler(ev) {
|
|
91
|
-
const payment = parseFloat(ev);
|
|
90
|
+
const payment = parseFloat(ev.payment);
|
|
92
91
|
|
|
93
92
|
if (isNaN(payment))
|
|
94
93
|
console.error(' ! Failed to parse payment:', payment);
|
|
@@ -96,27 +95,44 @@ exports.hook = function hookWorkerEvents$$hook(worker, options)
|
|
|
96
95
|
console.log(` . Payment: ${payment.toFixed(3)} ⊇`);
|
|
97
96
|
};
|
|
98
97
|
|
|
99
|
-
workerEventHandlers.
|
|
98
|
+
workerEventHandlers.fetchStart = function fetchStartHandler() {
|
|
100
99
|
options.verbose && console.log(' * Fetching slices...');
|
|
101
100
|
};
|
|
102
101
|
|
|
103
102
|
workerEventHandlers.fetch = function fetchHandler(ev) {
|
|
103
|
+
var slicesFetched;
|
|
104
|
+
|
|
104
105
|
if (ev instanceof Error)
|
|
106
|
+
{
|
|
105
107
|
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;
|
|
106
113
|
else
|
|
107
|
-
|
|
114
|
+
{
|
|
115
|
+
const task = ev;
|
|
116
|
+
slicesFetched = task.slices.length;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
options.verbose && console.log(' . Fetched', slicesFetched, 'slices');
|
|
108
120
|
};
|
|
109
121
|
|
|
122
|
+
workerEventHandlers.fetchError = function fetchErrorHandler(ev) {
|
|
123
|
+
console.log(' ! Failed to fetch slices:', ev);
|
|
124
|
+
};
|
|
110
125
|
|
|
111
|
-
workerEventHandlers.
|
|
126
|
+
workerEventHandlers.submitStart = function submitStartHandler() {
|
|
112
127
|
options.verbose >= 2 && console.log(' * Submitting results...');
|
|
113
128
|
};
|
|
114
129
|
|
|
115
|
-
workerEventHandlers.
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
130
|
+
workerEventHandlers.submit = function submitHandler() {
|
|
131
|
+
options.verbose >= 2 && console.log(' . Submitted');
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
workerEventHandlers.submitError = function submitErrorHandler(ev) {
|
|
135
|
+
console.log(' ! Failed to submit results:', ev);
|
|
120
136
|
};
|
|
121
137
|
|
|
122
138
|
/* Register the appropriate event handlers on the worker and on each sandbox. The handlers are
|
|
@@ -128,14 +144,14 @@ exports.hook = function hookWorkerEvents$$hook(worker, options)
|
|
|
128
144
|
* called `sandboxData` which is just arbitrary storage for the eventHandlers' use, eg for memos.
|
|
129
145
|
*/
|
|
130
146
|
for (let eventName in workerEventHandlers)
|
|
131
|
-
worker.
|
|
147
|
+
worker.addEventListener(eventName, workerEventHandlers[eventName]);
|
|
132
148
|
|
|
133
149
|
worker.on('sandbox', function newSandboxHandler(sandbox) {
|
|
134
150
|
const sandboxData = {
|
|
135
151
|
shortId: sandbox.id.toString(10).padStart(3)
|
|
136
152
|
};
|
|
137
153
|
for (let eventName in sandboxEventHandlers)
|
|
138
|
-
sandbox.
|
|
154
|
+
sandbox.addEventListener(eventName, (...args) => sandboxEventHandlers[eventName](sandbox, sandboxData, ...args));
|
|
139
155
|
});
|
|
140
156
|
|
|
141
157
|
exports.sandboxEventHandlers = sandboxEventHandlers;
|
package/lib/startWorkerLogger.js
CHANGED
|
@@ -36,10 +36,7 @@ function getLogger(options)
|
|
|
36
36
|
catch (error)
|
|
37
37
|
{
|
|
38
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
|
-
}
|
|
39
|
+
throw new Error(`Unknown outputMode "${options.outputMode}"`);
|
|
43
40
|
throw error;
|
|
44
41
|
}
|
|
45
42
|
}
|
|
@@ -126,5 +123,5 @@ function format(...argv)
|
|
|
126
123
|
* Options for util.inspect. Loggers which cannot deal with colours should force this false.
|
|
127
124
|
*/
|
|
128
125
|
exports.inspectOptions = {
|
|
129
|
-
colors: process.stdout.
|
|
126
|
+
colors: process.stdout.hasColors() || process.env.FORCE_COLOR,
|
|
130
127
|
};
|
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-7",
|
|
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": "
|
|
40
|
+
"dcp-client": "4.2.32",
|
|
41
41
|
"semver": "^7.3.8",
|
|
42
42
|
"syslog-client": "1.1.1"
|
|
43
43
|
},
|
|
@@ -46,15 +46,7 @@
|
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@kingsds/eslint-config": "^1.0.1",
|
|
49
|
-
"eslint": "
|
|
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
|
-
}
|
|
49
|
+
"eslint": "7.30.0"
|
|
58
50
|
},
|
|
59
51
|
"engines": {
|
|
60
52
|
"node": ">=16",
|
package/lib/utils.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
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;
|