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