-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdcp.js
executable file
·67 lines (51 loc) · 1.79 KB
/
dcp.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env node
const SCHEDULER_URL = new URL('http://scheduler.will.office.kingsds.network');
const workFunctionModule = require('./workFunction');
const fs = require('fs').promises;
/** Main program entry point */
async function main() {
const compute = require('dcp/compute');
const wallet = require('dcp/wallet');
let startTime;
const args = process.argv.slice(2);
let fileNameReadPromises = [];
let data;
for (let i = 0; i < args.length; i++) {
fileNameReadPromises.push(fs.readFile(args[i], 'utf8'));
}
try {
data = await Promise.all(fileNameReadPromises);
} catch (error) {
console.log('problem finding file');
console.log(error);
process.exit(1);
}
const job = compute.for(
data,
workFunctionModule.workFunction,
);
job.on('accepted', () => { console.log(` - Job ${job.id} accepted`); startTime = Date.now(); });
job.on('readystatechange', (arg) => { console.log(`new ready state: ${arg}`) });
job.on('result', (ev) => {
const time = Math.round((Date.now() - startTime) / 100) / 10;
console.log(` - Received result for slice ${ev.sliceNumber} at ${time}s`);
console.log(` * Wow! ${ev.result} is such a pretty colour!`);
});
job.public.name = 'one job - red';
console.log(job.computeGroups);
const ks = await wallet.get(); /* usually loads ~/.dcp/default.keystore */
job.setPaymentAccountKeystore(ks);
const results = Array.from(await job.localExec());
// const results = Array.from(await job.exec());
console.log('results=', results);
debugger;
for (let i = 0; i < results.length; i++) {
await fs.writeFile(`./build/asm-output${i}.S`, results[i]);
}
}
/* Initialize DCP Client and run main() */
require('dcp-client')
.init(SCHEDULER_URL)
.then(main)
.catch(console.error)
.finally(process.exit);