add support for LinkValidator

This commit is contained in:
2022-12-09 09:59:11 +01:00
parent 82b297fdd3
commit 7fea859e29
3 changed files with 60 additions and 37 deletions
+19 -3
View File
@@ -3,8 +3,11 @@ const {_android: android} = require("playwright");
const alert = require("alert");
const LinkValidator = require("./workers/LinkValidator");
const mongoManager = new MongoManager();
const schedule = require('node-schedule');
let canContinue = true;
function validateLinks() {
mongoManager.connect().then(r => {
android.devices().then((devices) => {
if (devices.length === 0) {
alert("未找到连接的设备");
@@ -14,15 +17,18 @@ mongoManager.connect().then(r => {
let segmentNumber = list.length / devices.length;
console.log("connected device number:" + devices.length)
console.log("segmentNumber:" + segmentNumber)
canContinue = false;
for (let i = 0; i < devices.length; i++) {
startWithList(list.slice(i * segmentNumber, segmentNumber * (i + 1)), devices[i]).then(result => {
console.log("stop")
canContinue = true;
})
}
})
})
});
}
async function startWithList(listOfUrls, device) {
await listOfUrls.reduce(async (promise, urlToValidate) => {
@@ -34,4 +40,14 @@ async function startWithList(listOfUrls, device) {
await commandor.loadPage()
console.log("next");
}, Promise.resolve());
}
}
mongoManager.connect().then(r => {
const job = schedule.scheduleJob('*/1 * * * *', function () {
if (canContinue) {
validateLinks()
} else {
console.log("job is executing, ignored")
}
})
});