attribute automatically the port
This commit is contained in:
+32
-9
@@ -4,6 +4,7 @@ const CommandorPage = require("./workers/CommandorPage");
|
||||
const {MongoManager, formatDate} = require("./workers/mongo_manager");
|
||||
const alert = require('alert');
|
||||
const schedule = require("node-schedule");
|
||||
const {execSync} = require("child_process");
|
||||
|
||||
const mongoManager = new MongoManager();
|
||||
const SEVEN_DAYS_IN_S = 3600 * 24 * 7;
|
||||
@@ -12,7 +13,11 @@ let excelUtil = new ExcelUtil();
|
||||
let collectionName = formatDate(new Date())
|
||||
// device_to_excludes = ["47e7e36b", "e30eb015"]
|
||||
// device_to_excludes = ["47e7e36b"]
|
||||
// device_to_excludes = ["J4AXB761H2322WJ"]
|
||||
device_to_excludes = []
|
||||
attributedPorts = []
|
||||
const device_port_info = new Map();
|
||||
startPort = 9000
|
||||
|
||||
async function filterAlreadyBookedContacts(contactList) {
|
||||
let alreadyBookedContacts = await mongoManager.getAllSuccessfulItemsForDay(collectionName);
|
||||
@@ -25,7 +30,7 @@ async function filterAlreadyBookedContacts(contactList) {
|
||||
return contactsToBook;
|
||||
}
|
||||
|
||||
async function filterAlreadyAccepteddContacts(contactList) {
|
||||
async function filterAlreadyAcceptedContacts(contactList) {
|
||||
let alreadyBookedContacts = await mongoManager.getAllAcceptedAppointments();
|
||||
let contactsToBook = [];
|
||||
contactList.forEach((contact) => {
|
||||
@@ -112,20 +117,19 @@ async function needToBook(contact, mongoManager) {
|
||||
return needToBook
|
||||
}
|
||||
|
||||
async function startBook(contactPojo, device, selectedStore, audioAnalyse, alertBeep) {
|
||||
async function startBook(contactPojo, device, selectedStore, audioAnalyse, alertBeep, port) {
|
||||
console.log(`model: ${device.model()}`);
|
||||
console.log(`serial: ${device.serial()}`);
|
||||
if (await needToBook(contactPojo, mongoManager)) {
|
||||
let commandor = new CommandorPage(contactPojo, device, mongoManager, selectedStore, audioAnalyse, alertBeep);
|
||||
let commandor = new CommandorPage(contactPojo, device, mongoManager, selectedStore, audioAnalyse, alertBeep, port);
|
||||
//read contacts form excel
|
||||
let port = 9222;
|
||||
return await commandor.loadPage(port);
|
||||
return await commandor.loadPage();
|
||||
} else {
|
||||
console.log("do not send request --> skip")
|
||||
}
|
||||
}
|
||||
|
||||
async function startWithList(contacts, device, selectedStore, audioAnalyse, alertBeep) {
|
||||
async function startWithList(contacts, device, selectedStore, audioAnalyse, alertBeep, port) {
|
||||
let duplicatedList = [].concat(contacts).concat(contacts).concat(contacts)
|
||||
// let duplicatedList = [].concat(contacts)
|
||||
await duplicatedList.reduce(async (promise, contactPojo) => {
|
||||
@@ -133,7 +137,7 @@ async function startWithList(contacts, device, selectedStore, audioAnalyse, aler
|
||||
// The first iteration uses an already resolved Promise
|
||||
// so, it will immediately continue.
|
||||
await promise;
|
||||
const contents = await startBook(contactPojo, device, selectedStore, audioAnalyse, alertBeep);
|
||||
const contents = await startBook(contactPojo, device, selectedStore, audioAnalyse, alertBeep, port);
|
||||
console.log(contents);
|
||||
}, Promise.resolve());
|
||||
}
|
||||
@@ -161,9 +165,26 @@ async function startBookWithNumbers(startNumber, endNumber, selectedStore, pathT
|
||||
alert("联系人数为0")
|
||||
return
|
||||
}
|
||||
|
||||
function startForwordingForDevice(device) {
|
||||
const execSync = require('child_process').execSync;
|
||||
// get attributed port
|
||||
let attributedPort = device_port_info[device.serial()]
|
||||
if (attributedPort) {
|
||||
const output = execSync('adb -s ' + device.serial() + " forward tcp:" + attributedPort + " localabstract:chrome_devtools_remote", {encoding: 'utf-8'}); // the default is 'buffer'
|
||||
console.log('Output was:\n', output);
|
||||
} else {
|
||||
attributedPort = startPort;
|
||||
startPort++;
|
||||
const output = execSync('adb -s ' + device.serial() + " forward tcp:" + attributedPort + " localabstract:chrome_devtools_remote", {encoding: 'utf-8'}); // the default is 'buffer'
|
||||
console.log('Output was:\n', output);
|
||||
}
|
||||
return attributedPort
|
||||
}
|
||||
|
||||
mongoManager.connect().then(r => {
|
||||
filterAlreadyBookedContacts(contactList).then((listToBook) => {
|
||||
filterAlreadyAccepteddContacts(listToBook).then(notAcceptedContacts => {
|
||||
filterAlreadyAcceptedContacts(listToBook).then(notAcceptedContacts => {
|
||||
filterBlacklistedContacts(notAcceptedContacts).then(listWithoutBlackContact => {
|
||||
console.log("number of contacts to book:" + listWithoutBlackContact.length)
|
||||
android.devices().then((devices) => {
|
||||
@@ -176,7 +197,9 @@ async function startBookWithNumbers(startNumber, endNumber, selectedStore, pathT
|
||||
console.log("connected device number:" + filteredDeviceList.length)
|
||||
console.log("segmentNumber:" + segmentNumber)
|
||||
for (let i = 0; i < filteredDeviceList.length; i++) {
|
||||
startWithList(listWithoutBlackContact.slice(i * segmentNumber, segmentNumber * (i + 1)), filteredDeviceList[i], selectedStore, audioAnalyse, alertBeep);
|
||||
let device = filteredDeviceList[i];
|
||||
let port = startForwordingForDevice(device)
|
||||
startWithList(listWithoutBlackContact.slice(i * segmentNumber, segmentNumber * (i + 1)), device, selectedStore, audioAnalyse, alertBeep, port);
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user