From 1f0a6bb8051b4dbca16b85b8ec5add51a169bf10 Mon Sep 17 00:00:00 2001 From: Lei PAN Date: Tue, 5 Mar 2024 11:34:32 +0100 Subject: [PATCH] add more logs --- src/appointment.js | 72 ++++++++++++++++++++++++--------------------- src/queue/Sender.js | 4 ++- 2 files changed, 41 insertions(+), 35 deletions(-) diff --git a/src/appointment.js b/src/appointment.js index 1d2afb3..c3a3077 100644 --- a/src/appointment.js +++ b/src/appointment.js @@ -193,6 +193,7 @@ async function startBookWithNumbers(startNumber, endNumber, selectedStore, pathT } function startForwordingForDevice(device) { + console.log("startForwordingForDevice() called") const execSync = require('child_process').execSync; // get attributed port let attributedPort = device_port_info[device.serial()] @@ -217,41 +218,44 @@ async function startBookWithNumbers(startNumber, endNumber, selectedStore, pathT let sender = new Sender() sender.initConnection().then((r) => { console.log("queue connected") - mongoManager.connect().then(r => { - filterAlreadyBookedContacts(contactList).then((listToBook) => { - filterAlreadyAcceptedContacts(listToBook).then(notAcceptedContacts => { - filterBlacklistedContacts(notAcceptedContacts).then(listWithoutBlackContact => { - console.log("number of contacts to book:" + listWithoutBlackContact.length) - android.devices().then((devices) => { - if (devices.length === 0) { - alert("未找到连接的设备"); - return - } - let device_to_excludes = three_to_excludes; - if (excludeMode === DeviceExcludeMode.FOUR) { - device_to_excludes = four_to_excludes; - } else if (excludeMode === DeviceExcludeMode.NINE) { - device_to_excludes = nine_to_excludes; - } else if (excludeMode === DeviceExcludeMode.SEVEN) { - device_to_excludes = seven_to_excludes - } else if (excludeMode === DeviceExcludeMode.SIX) { - device_to_excludes = six_to_excludes - } - filteredDeviceList = devices.filter(device => !device_to_excludes.includes(device.serial())) - let segmentNumber = listWithoutBlackContact.length / filteredDeviceList.length; - console.log("connected device number:" + filteredDeviceList.length) - console.log("segmentNumber:" + segmentNumber) - for (let i = 0; i < filteredDeviceList.length; i++) { - let device = filteredDeviceList[i]; - let port = startForwordingForDevice(device) - startWithList(listWithoutBlackContact.slice(i * segmentNumber, segmentNumber * (i + 1)), device, sender, selectedStore, audioAnalyse, alertBeep, port); - } - }) + console.log("connect to mongodb") + mongoManager.connect().then(r => { + console.log("successfully connected to mongodb") + + filterAlreadyBookedContacts(contactList).then((listToBook) => { + filterAlreadyAcceptedContacts(listToBook).then(notAcceptedContacts => { + filterBlacklistedContacts(notAcceptedContacts).then(listWithoutBlackContact => { + console.log("number of contacts to book:" + listWithoutBlackContact.length) + android.devices().then((devices) => { + if (devices.length === 0) { + alert("未找到连接的设备"); + return + } + let device_to_excludes = three_to_excludes; + if (excludeMode === DeviceExcludeMode.FOUR) { + device_to_excludes = four_to_excludes; + } else if (excludeMode === DeviceExcludeMode.NINE) { + device_to_excludes = nine_to_excludes; + } else if (excludeMode === DeviceExcludeMode.SEVEN) { + device_to_excludes = seven_to_excludes + } else if (excludeMode === DeviceExcludeMode.SIX) { + device_to_excludes = six_to_excludes + } + filteredDeviceList = devices.filter(device => !device_to_excludes.includes(device.serial())) + let segmentNumber = listWithoutBlackContact.length / filteredDeviceList.length; + console.log("connected device number:" + filteredDeviceList.length) + console.log("segmentNumber:" + segmentNumber) + for (let i = 0; i < filteredDeviceList.length; i++) { + let device = filteredDeviceList[i]; + let port = startForwordingForDevice(device) + startWithList(listWithoutBlackContact.slice(i * segmentNumber, segmentNumber * (i + 1)), device, sender, selectedStore, audioAnalyse, alertBeep, port); + } }) - } - ) - }) - }); + }) + } + ) + }) + }); }) } diff --git a/src/queue/Sender.js b/src/queue/Sender.js index 3cccd6e..e665617 100644 --- a/src/queue/Sender.js +++ b/src/queue/Sender.js @@ -9,7 +9,9 @@ class Sender { connection; async initConnection() { - this.connection = await amqp.connect(QUEUE_HOST); + this.connection = await amqp.connect(QUEUE_HOST, { + timeout: 15000 + }); this.channel = await this.connection.createChannel(); await this.channel.assertQueue(REQUEST_DATA_QUEUE_FR, {persistent: true}); }