-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
35 lines (30 loc) · 1.02 KB
/
Copy pathindex.js
File metadata and controls
35 lines (30 loc) · 1.02 KB
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
import { validateConfigFile } from './utils/validation.js';
import { Worker } from 'worker_threads';
import { logInfo, logError } from './utils/logger.js';
async function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async function main() {
try {
const configList = await validateConfigFile();
if (!configList.length) {
logError('No valid configurations found!');
return;
}
while (true) {
logInfo('Starting new check cycle...');
const workers = configList.map(config => {
return new Promise((resolve) => {
const worker = new Worker('./worker.js', { workerData: config });
worker.on('exit', resolve);
});
});
await Promise.all(workers);
logInfo('Sleeping for 30 seconds...');
await sleep(30000); // Sleep for 1 minute
}
} catch (e) {
logError(`Main function error: ${e}`);
}
}
main();