testilo 7.0.4 → 7.0.6
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/README.md +3 -3
- package/aim.js +10 -3
- package/call.js +7 -7
- package/merge.js +19 -37
- package/package.json +1 -1
- package/score.js +1 -1
package/README.md
CHANGED
|
@@ -107,7 +107,7 @@ Execution by a module:
|
|
|
107
107
|
|
|
108
108
|
```javaScript
|
|
109
109
|
const {merge} = require('testilo/merge');
|
|
110
|
-
merge('tp25', 'weborgs')
|
|
110
|
+
merge('tp25', 'weborgs', 'developer@w3.org')
|
|
111
111
|
.then(() => {
|
|
112
112
|
console.log('Merger complete');
|
|
113
113
|
});
|
|
@@ -116,10 +116,10 @@ merge('tp25', 'weborgs')
|
|
|
116
116
|
Execution by a user:
|
|
117
117
|
|
|
118
118
|
```bash
|
|
119
|
-
node call merge tp25 weborgs
|
|
119
|
+
node call merge tp25 weborgs developer@w3.org
|
|
120
120
|
```
|
|
121
121
|
|
|
122
|
-
In these examples, a copy of the script file named `tp25.json` in the `SCRIPTDIR` directory is aimed at all the hosts in the batch file named `weborgs.json` in the `BATCHDIR` directory, and the resulting
|
|
122
|
+
In these examples, a copy of the script file named `tp25.json` in the `SCRIPTDIR` directory is aimed at all the hosts in the batch file named `weborgs.json` in the `BATCHDIR` directory, and the resulting jobs are saved in the `JOBDIR` directory. Each job has a `sources` property that identifies an email address to be notified after the job has been run.
|
|
123
123
|
|
|
124
124
|
### `score`
|
|
125
125
|
|
package/aim.js
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
/*
|
|
2
2
|
aim.js
|
|
3
3
|
Module for aiming a script at a host.
|
|
4
|
+
Arguments:
|
|
5
|
+
0. script object.
|
|
6
|
+
1. host object.
|
|
7
|
+
2. email address to be notified of completion.
|
|
8
|
+
3?. time stamp.
|
|
4
9
|
*/
|
|
5
10
|
|
|
6
11
|
// ########## FUNCTIONS
|
|
@@ -8,7 +13,7 @@
|
|
|
8
13
|
// Returns a string representing the date and time.
|
|
9
14
|
const nowString = () => (new Date()).toISOString().slice(0, 19);
|
|
10
15
|
// Returns a script, aimed at a host, as a job.
|
|
11
|
-
exports.aim = (script, host, requester) => {
|
|
16
|
+
exports.aim = (script, host, requester, timeStamp = '') => {
|
|
12
17
|
// Initialize a job based on the script.
|
|
13
18
|
const job = JSON.parse(JSON.stringify(script));
|
|
14
19
|
// Make all url commands in the script visit the host.
|
|
@@ -22,11 +27,13 @@ exports.aim = (script, host, requester) => {
|
|
|
22
27
|
// Add source information to the script.
|
|
23
28
|
job.sources = {
|
|
24
29
|
script: script.id,
|
|
30
|
+
batch: '',
|
|
25
31
|
host,
|
|
26
32
|
requester
|
|
27
33
|
}
|
|
28
|
-
// Create a job-creation time stamp.
|
|
29
|
-
|
|
34
|
+
// Create a job-creation time stamp, if not specified.
|
|
35
|
+
|
|
36
|
+
timeStamp = timeStamp || Math.floor((Date.now() - Date.UTC(2022, 1)) / 2000).toString(36);
|
|
30
37
|
// Change the script ID to a job ID.
|
|
31
38
|
job.id = `${timeStamp}-${script.id}-${host.id}`;
|
|
32
39
|
// Add the job-creation time to the script.
|
package/call.js
CHANGED
|
@@ -71,8 +71,8 @@ const callAim = async (scriptName, hostURL, hostName, hostID, requester) => {
|
|
|
71
71
|
console.log(`Script ${scriptID} aimed at ${hostName} saved as job ${jobID}.json in ${jobDir}`);
|
|
72
72
|
};
|
|
73
73
|
// Fulfills a merger request.
|
|
74
|
-
const callMerge = async (scriptName, batchName) => {
|
|
75
|
-
await merge(scriptName, batchName);
|
|
74
|
+
const callMerge = async (scriptName, batchName, requester) => {
|
|
75
|
+
await merge(scriptName, batchName, requester);
|
|
76
76
|
console.log(`Batch ${batchName}.json merged into script ${scriptName} in ${jobDir}`);
|
|
77
77
|
};
|
|
78
78
|
// Fulfills a scoring request.
|
|
@@ -93,15 +93,15 @@ const callScore = async (scoreProcID, reportIDStart = '') => {
|
|
|
93
93
|
// If it exists:
|
|
94
94
|
if (rawReportName) {
|
|
95
95
|
// Score it.
|
|
96
|
-
const rawReportJSON = await fs.readFile(`${rawDir}/${rawReportName}
|
|
96
|
+
const rawReportJSON = await fs.readFile(`${rawDir}/${rawReportName}`, 'utf8');
|
|
97
97
|
const rawReport = JSON.parse(rawReportJSON);
|
|
98
98
|
const {scorer} = require(`${scoreProcDir}/${scoreProcID}.js`);
|
|
99
|
-
const scoredReport = score(scorer, rawReport);
|
|
99
|
+
const scoredReport = await score(scorer, rawReport);
|
|
100
100
|
// Save it, scored.
|
|
101
101
|
await fs.writeFile(
|
|
102
|
-
`${scoredDir}/${scoredReport.id}.json`, JSON.stringify(scoredReport, null, 2)
|
|
102
|
+
`${scoredDir}/${scoredReport.job.id}.json`, JSON.stringify(scoredReport, null, 2)
|
|
103
103
|
);
|
|
104
|
-
console.log(`
|
|
104
|
+
console.log(`Scored report ${rawReport.job.id} saved in ${scoredDir}`);
|
|
105
105
|
}
|
|
106
106
|
// Otherwise, i.e. if it does not exist:
|
|
107
107
|
else {
|
|
@@ -238,7 +238,7 @@ if (fn === 'aim' && fnArgs.length === 5) {
|
|
|
238
238
|
console.log('Execution completed');
|
|
239
239
|
});
|
|
240
240
|
}
|
|
241
|
-
else if (fn === 'merge' && fnArgs.length ===
|
|
241
|
+
else if (fn === 'merge' && fnArgs.length === 3) {
|
|
242
242
|
callMerge(... fnArgs)
|
|
243
243
|
.then(() => {
|
|
244
244
|
console.log('Execution completed');
|
package/merge.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
/*
|
|
2
2
|
merge.js
|
|
3
|
-
Merges a batch and a script to produce
|
|
3
|
+
Merges a batch and a script to produce jobs.
|
|
4
4
|
Arguments:
|
|
5
5
|
0. base of name of script located in process.env.SCRIPTDIR.
|
|
6
6
|
1. base of name of batch located in process.env.BATCHDIR.
|
|
7
|
+
2. email address to be notified of completion.
|
|
7
8
|
Usage example:
|
|
8
|
-
node merge
|
|
9
|
-
Note: The subdirectory for
|
|
9
|
+
node merge tp25 weborgs developer@w3.org
|
|
10
|
+
Note: The subdirectory for jobs will be created if it does not exist.
|
|
10
11
|
*/
|
|
11
12
|
|
|
12
13
|
// ########## IMPORTS
|
|
@@ -15,6 +16,8 @@
|
|
|
15
16
|
require('dotenv').config();
|
|
16
17
|
// Module to read and write files.
|
|
17
18
|
const fs = require('fs/promises');
|
|
19
|
+
// Module to aim a script at a host.
|
|
20
|
+
const {aim} = require('./aim');
|
|
18
21
|
|
|
19
22
|
// ########## CONSTANTS
|
|
20
23
|
|
|
@@ -24,46 +27,25 @@ const jobDir = process.env.JOBDIR || 'watch';
|
|
|
24
27
|
|
|
25
28
|
// ########## FUNCTIONS
|
|
26
29
|
|
|
27
|
-
//
|
|
28
|
-
|
|
29
|
-
//
|
|
30
|
-
exports.merge = async (scriptName, batchName) => {
|
|
30
|
+
// Merges a batch into a script and writes jobs.
|
|
31
|
+
exports.merge = async (scriptName, batchName, requester) => {
|
|
32
|
+
// Get the script and the batch.
|
|
31
33
|
const scriptJSON = await fs.readFile(`${scriptDir}/${scriptName}.json`, 'utf8');
|
|
32
34
|
const batchJSON = await fs.readFile(`${batchDir}/${batchName}.json`, 'utf8');
|
|
33
35
|
const script = JSON.parse(scriptJSON);
|
|
34
36
|
const batch = JSON.parse(batchJSON);
|
|
35
|
-
// Create the watch directory if it does not exist.
|
|
36
|
-
await fs.mkdir(jobDir, {recursive: true});
|
|
37
|
-
// Create a job-creation time stamp.
|
|
38
37
|
const timeStamp = Math.floor((Date.now() - Date.UTC(2022, 1)) / 2000).toString(36);
|
|
38
|
+
// Create the job directory if it does not exist.
|
|
39
|
+
await fs.mkdir(jobDir, {recursive: true});
|
|
39
40
|
// For each host in the batch:
|
|
40
41
|
const {hosts} = batch;
|
|
41
|
-
const
|
|
42
|
-
//
|
|
43
|
-
const
|
|
44
|
-
//
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
command.which = host.which;
|
|
49
|
-
command.what = host.what;
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
// Add source information to the script.
|
|
53
|
-
newScript.sources = {
|
|
54
|
-
script: script.id,
|
|
55
|
-
batch: batch.id
|
|
56
|
-
}
|
|
57
|
-
// Add the job-creation time to the script.
|
|
58
|
-
newScript.jobCreationTime = nowString();
|
|
59
|
-
// Change the script ID to a job ID.
|
|
60
|
-
newScript.id = `${timeStamp}-${newScript.id}-${host.id}`;
|
|
61
|
-
// Return the host-specific script.
|
|
62
|
-
return newScript;
|
|
63
|
-
});
|
|
64
|
-
// Write the host-specific scripts.
|
|
65
|
-
for (const newScript of newScripts) {
|
|
66
|
-
await fs.writeFile(`${jobDir}/${newScript.id}.json`, JSON.stringify(newScript, null, 2));
|
|
42
|
+
for (const host of hosts) {
|
|
43
|
+
// Aim the script at the host.
|
|
44
|
+
const job = await aim(script, host, requester, timeStamp);
|
|
45
|
+
// Add the batch name to the job.
|
|
46
|
+
job.sources.batch = batchName;
|
|
47
|
+
// Save the job.
|
|
48
|
+
await fs.writeFile(`${jobDir}/${job.id}.json`, JSON.stringify(job, null, 2));
|
|
67
49
|
};
|
|
68
|
-
console.log(`Merger completed.
|
|
50
|
+
console.log(`Merger completed. Job count: ${hosts.length}. Time stamp ${timeStamp}.`);
|
|
69
51
|
};
|
package/package.json
CHANGED
package/score.js
CHANGED
|
@@ -14,6 +14,6 @@ exports.score = async (scoreProc, rawReport) => {
|
|
|
14
14
|
const scoredReport = JSON.parse(JSON.stringify(rawReport));
|
|
15
15
|
// Score it.
|
|
16
16
|
await scoreProc(scoredReport);
|
|
17
|
-
console.log(`Report ${rawReport.id} scored`);
|
|
17
|
+
console.log(`Report ${rawReport.job.id} scored`);
|
|
18
18
|
return scoredReport;
|
|
19
19
|
};
|