added retry for puppeteering

master
cheetah 2 years ago
parent d1d569dadf
commit a866aa79c4

@ -33,7 +33,7 @@ class eMessagePuppeteerConnector extends Connector {
}
}
let sendPromise = new Promise(async (res, rej) => {
let sendPromise = () => new Promise(async (res, rej) => {
const browser = await puppeteer.launch({ headless: true })
this.connectorRegistry.reportState(msg, UUID, 'puppettering')
const page = await browser.newPage()
@ -44,29 +44,32 @@ class eMessagePuppeteerConnector extends Connector {
await page.select(serviceSelect, serviceName)
await page.click(serviceSelect)
await page.click(serviceSelect)
await sleep(1e3)
const selectServiceButton = 'input[name="pageSendForm:selectServiceButton"]'
await page.waitForSelector(selectServiceButton)
await page.click(selectServiceButton)
await sleep(1e3)
const pagerNumberInput = 'input[name="pageSendForm:pagerNumberInput"]'
await page.waitForSelector(pagerNumberInput)
await page.type(pagerNumberInput, identifier)
await sleep(1e3)
const validatePagerNumberButton = 'input[id="pageSendForm:validatePagerNumberButton"]'
await page.waitForSelector(validatePagerNumberButton)
await page.click(validatePagerNumberButton)
await sleep(1e3)
const pageContentInput = 'textarea[id="pageSendForm:pageContentInput"]'
await page.waitForSelector(pageContentInput)
await page.type(pageContentInput, payloadBuffer.toString('ascii'))
await sleep(1e3)
const sendPageButton = 'input[id="pageSendForm:sendPageButton"]'
await page.waitForSelector(sendPageButton)
await page.click(sendPageButton)
await sleep(1e3)
const messageSentResult = 'span[id="pageSendForm:messageSentResult"]'
await page.waitForSelector(messageSentResult)
@ -75,22 +78,34 @@ class eMessagePuppeteerConnector extends Connector {
let value = await page.evaluate(el => el.textContent, $messageSentResult)
// pageSendForm:messageSentResult
if (value.indexOf("Meldung : OK") > -1) {
this.connectorRegistry.reportState(msg, UUID, 'transit')
await browser.close()
return res(true)
} else {
this.connectorRegistry.reportState(msg, UUID, 'fail')
await browser.close()
return rej(value)
}
})
sendPromise
try {
await sendPromise()
} catch (e1) {
console.error(e1)
try {
await sendPromise()
} catch (e2) {
console.error(e2)
await sendPromise()
.then(_=>{
this.connectorRegistry.reportState(msg, UUID, 'transit')
return true
})
.catch((err) => {
console.error(err)
this.connectorRegistry.reportFail(msg, UUID)
return false
})
}
}
}
}
module.exports = eMessagePuppeteerConnector
Loading…
Cancel
Save