dcp-worker 4.4.0 → 4.4.2
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 +4 -4
- package/lib/utils.js +5 -12
- package/lib/web-iface.js +1 -1
- package/package.json +4 -6
- package/www/hud/small-dark.html +80 -14
package/bin/dcp-worker
CHANGED
|
@@ -581,9 +581,6 @@ async function main()
|
|
|
581
581
|
|
|
582
582
|
worker.runInfo.type = 'dcp-worker';
|
|
583
583
|
worker.on('warning', (...payload) => console.warn (...payload));
|
|
584
|
-
worker.on('stop', () => { console.log(' - Worker is stopping'); workerIsStopping = true });
|
|
585
|
-
worker.on('end', () => { console.log(' * Worker has stopped') });
|
|
586
|
-
worker.on('job', job => console.log(` . Job: ${job.name} ${job.id.slice(0,8)} ${job.description || ''} ${job.link || ''}`));
|
|
587
584
|
worker.on('claim', amount => console.log(` . transfered ${amount} ⊇ to ${worker.config.paymentAddress}`));
|
|
588
585
|
|
|
589
586
|
await processCliOptsPhase2(remainArgv, operatingMode, loggingOptions);
|
|
@@ -645,7 +642,7 @@ async function main()
|
|
|
645
642
|
if ((workerInfo = await require('../lib/worker-info').getEvaluatorInformation(sandboxConfig)))
|
|
646
643
|
break;
|
|
647
644
|
if (i === 0 && operatingMode.unmanaged !== true)
|
|
648
|
-
utils.noteWorkerStart();
|
|
645
|
+
utils.noteWorkerStart(worker);
|
|
649
646
|
if (performance.now() - ts > 100)
|
|
650
647
|
console.throb();
|
|
651
648
|
await a$sleep(Math.max(i + 1, 10) / 4);
|
|
@@ -784,6 +781,9 @@ async function main()
|
|
|
784
781
|
console.info(` ! not claming earnings in the amount of ${amount} ⊇ (can claim later)`);
|
|
785
782
|
}
|
|
786
783
|
|
|
784
|
+
worker.on('stop', () => { console.log(' - Worker is stopping'); workerIsStopping = true });
|
|
785
|
+
worker.on('end', () => { console.log(' * Worker has stopped') });
|
|
786
|
+
worker.on('job', job => console.log(` . Job: ${job.name} ${job.id.slice(0,8)} ${job.description || ''} ${job.link || ''}`));
|
|
787
787
|
console.info(' * Ready.\n');
|
|
788
788
|
await worker.start();
|
|
789
789
|
} /* main() */
|
package/lib/utils.js
CHANGED
|
@@ -382,20 +382,13 @@ exports.patchWorkerId = async function patchWorkerId(lookupFields)
|
|
|
382
382
|
*/
|
|
383
383
|
exports.noteWorkerStart = async function noteWorkerStart(worker)
|
|
384
384
|
{
|
|
385
|
-
|
|
386
|
-
if (worker?.config?.unmanaged)
|
|
385
|
+
if (worker.config?.unmanaged)
|
|
387
386
|
return;
|
|
388
387
|
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
workerOpaqueId: DistributiveWorker.obtainWorkerId(),
|
|
394
|
-
lastStartTime: new Date(),
|
|
395
|
-
status: 'running',
|
|
396
|
-
}
|
|
397
|
-
});
|
|
398
|
-
exports.noteWorkerStart.db = db;
|
|
388
|
+
return worker.updateRunInfo({
|
|
389
|
+
lastStartTime: new Date(),
|
|
390
|
+
status: 'running',
|
|
391
|
+
}, true);
|
|
399
392
|
}
|
|
400
393
|
|
|
401
394
|
/**
|
package/lib/web-iface.js
CHANGED
|
@@ -377,7 +377,7 @@ function filenameFromPathname(docroot, pathname, strip)
|
|
|
377
377
|
pathname = pathname.slice(strip.length);
|
|
378
378
|
}
|
|
379
379
|
const filename = path.join(docroot, pathname);
|
|
380
|
-
if (!filename.startsWith(docroot) || filename[docroot.length] !==
|
|
380
|
+
if (!filename.startsWith(docroot) || filename[docroot.length] !== path.sep)
|
|
381
381
|
throw new Error(`invalid pathname ${pathname} ${filename} ${docroot}`);
|
|
382
382
|
return filename;
|
|
383
383
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dcp-worker",
|
|
3
|
-
"version": "4.4.
|
|
3
|
+
"version": "4.4.2",
|
|
4
4
|
"description": "Node.js Worker for Distributive Compute Platform",
|
|
5
5
|
"main": "bin/dcp-worker",
|
|
6
6
|
"keywords": [
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"blessed": "0.1.81",
|
|
40
40
|
"blessed-contrib": "4.11.0",
|
|
41
41
|
"chalk": "4.1.2",
|
|
42
|
-
"dcp-client": "^5.
|
|
42
|
+
"dcp-client": "^5.6.0",
|
|
43
43
|
"kvin": "^9.0.0",
|
|
44
44
|
"posix-getopt": "1.2.1",
|
|
45
45
|
"semver": "7.7.3",
|
|
@@ -75,10 +75,8 @@
|
|
|
75
75
|
},
|
|
76
76
|
"dbus-next": {
|
|
77
77
|
"xml2js": "0.6.2",
|
|
78
|
-
"tar": "7.5.
|
|
79
|
-
"usocket":
|
|
80
|
-
"node-gyp": "10.0.1"
|
|
81
|
-
}
|
|
78
|
+
"tar": "7.5.11",
|
|
79
|
+
"usocket": "1.0.2"
|
|
82
80
|
}
|
|
83
81
|
}
|
|
84
82
|
}
|
package/www/hud/small-dark.html
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
<html lang="en">
|
|
11
11
|
<head>
|
|
12
12
|
<meta charset="UTF-8">
|
|
13
|
+
<meta name="viewport" content="width=device-width, height=device-height initial-scale=1">
|
|
13
14
|
<title>DCP Worker - HUD</title>
|
|
14
15
|
<link rel="stylesheet" type="text/css" href="./hud-common.css">
|
|
15
16
|
<script src="/etc/dcp-config.js"></script>
|
|
@@ -21,15 +22,17 @@
|
|
|
21
22
|
import * as hud from "./hud-common.mjs";
|
|
22
23
|
window.addEventListener('error', ev => dcp['dom-tk'].modals.alert(ev));
|
|
23
24
|
window.addEventListener('unhandledrejection', ev => dcp['dom-tk'].modals.alert(ev.reason));
|
|
25
|
+
document.body.style.height = window.innerHeight + 'px';
|
|
24
26
|
</script>
|
|
25
27
|
<style type="text/css">
|
|
26
28
|
HTML, BODY {
|
|
27
|
-
height:
|
|
28
|
-
width:
|
|
29
|
-
|
|
29
|
+
min-height: 100vh;
|
|
30
|
+
min-width: 100vh;
|
|
31
|
+
height: 100vh;
|
|
30
32
|
margin: 0;
|
|
31
33
|
padding: 0;
|
|
32
|
-
overflow:
|
|
34
|
+
overflow-x: hidden;
|
|
35
|
+
overflow-y: auto;
|
|
33
36
|
}
|
|
34
37
|
|
|
35
38
|
DIV#dcp-logo {
|
|
@@ -55,7 +58,7 @@ BODY[show-logo="false"] DIV#dcp-logo-header {
|
|
|
55
58
|
|
|
56
59
|
#loggerText {
|
|
57
60
|
white-space: pre-wrap;
|
|
58
|
-
position:
|
|
61
|
+
position: fixed;
|
|
59
62
|
bottom: 0;
|
|
60
63
|
max-height: 100%;
|
|
61
64
|
width: 100%;
|
|
@@ -63,7 +66,7 @@ BODY[show-logo="false"] DIV#dcp-logo-header {
|
|
|
63
66
|
overflow-y: scroll;
|
|
64
67
|
text-overflow: ellipsis;
|
|
65
68
|
text-wrap: nowrap;
|
|
66
|
-
padding:
|
|
69
|
+
padding: 15px;
|
|
67
70
|
}
|
|
68
71
|
|
|
69
72
|
TABLE
|
|
@@ -118,14 +121,76 @@ async function init()
|
|
|
118
121
|
el.textContent = String(bnTotal.plus(bnAmount));
|
|
119
122
|
});
|
|
120
123
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
124
|
+
//
|
|
125
|
+
// WORKER EVENTS
|
|
126
|
+
//
|
|
127
|
+
|
|
128
|
+
// Fired when fetching work from the scheduler
|
|
129
|
+
worker.on("fetch", ev => {
|
|
130
|
+
const jobIds = Object.keys(ev.jobs);
|
|
131
|
+
|
|
132
|
+
if (jobIds.length === 0) {
|
|
133
|
+
logger("[worker.fetch] No new work fetched; retrying in 7 seconds...");
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const sizeKB = (ev.fetchSize / 1024).toFixed(2);
|
|
138
|
+
logger(`[worker.fetch] fetchSize: ${sizeKB} KB`);
|
|
139
|
+
|
|
140
|
+
for (const jobId of jobIds) {
|
|
141
|
+
const job = ev.jobs[jobId];
|
|
142
|
+
const sliceCount = ev.slices[jobId] || 0;
|
|
143
|
+
|
|
144
|
+
logger(`jobId: ${jobId}\tname: ${job.name}\tdescription: ${job.description}\tlink: ${job.link}\tslicesFetched: ${sliceCount}`)
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
// Fired after a slice result is sent (or fails to send)
|
|
149
|
+
worker.on("result", (urlOrError, size, jobId) => {
|
|
150
|
+
if (urlOrError instanceof Error) {
|
|
151
|
+
logger(`[worker.result] job ${jobId} had error ${urlOrError.message}`);
|
|
152
|
+
} else {
|
|
153
|
+
logger(`[worker.result] job ${jobId} sent ${(size / 1024).toFixed(2)} KB to ${urlOrError || "scheduler"}`);
|
|
154
|
+
}
|
|
126
155
|
});
|
|
127
|
-
|
|
128
|
-
|
|
156
|
+
|
|
157
|
+
// Payment received for completed slices
|
|
158
|
+
let totalEarned = 0;
|
|
159
|
+
const totalEarnedEl = document.getElementById("total-earned");
|
|
160
|
+
worker.on("payment", (payment, paymentAccount, jobId, slice) => {
|
|
161
|
+
totalEarned += Number(payment);
|
|
162
|
+
if (totalEarnedEl) {
|
|
163
|
+
totalEarnedEl.textContent = `${totalEarned.toFixed(3)} ⊇`;
|
|
164
|
+
}
|
|
165
|
+
logger(
|
|
166
|
+
`[worker.payment] ` +
|
|
167
|
+
`payment: ${payment} ⊇, ` +
|
|
168
|
+
`depositAccount: ${paymentAccount}, ` +
|
|
169
|
+
`jobId: ${jobId}, ` +
|
|
170
|
+
`slice: ${slice}`
|
|
171
|
+
);
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
// Worker stop requested; shutdown starting
|
|
175
|
+
worker.on("stop", abort => {
|
|
176
|
+
logger("[worker.stop] worker preparing to shutdown...");
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
// Worker shutdown complete
|
|
180
|
+
worker.on("end", () => {
|
|
181
|
+
logger("[worker.end] worker fully stopped");
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
// Internal error occurred in worker
|
|
185
|
+
worker.on("error", err => {
|
|
186
|
+
logger(`[worker.error] ${error.code ? error.message+'; code='+error.code : error.message}`);
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
// Warning occurred in worker
|
|
190
|
+
worker.on("warning", warn => {
|
|
191
|
+
logger(`[worker.warning] ${JSON.stringify(warn, null, 2)}`);
|
|
192
|
+
});
|
|
193
|
+
|
|
129
194
|
}
|
|
130
195
|
|
|
131
196
|
const logLines = [];
|
|
@@ -133,7 +198,8 @@ const logSize = 100;
|
|
|
133
198
|
function logger(...args)
|
|
134
199
|
{
|
|
135
200
|
const logEl = $('#loggerText');
|
|
136
|
-
const
|
|
201
|
+
const ts = new Date().toLocaleTimeString();
|
|
202
|
+
const msg = `[${ts}] ` + args.map(arg => String(arg)).join(' ');
|
|
137
203
|
logLines.push(msg);
|
|
138
204
|
if (logLines.length === logSize)
|
|
139
205
|
logLines.shift();
|