This commit is contained in:
spiduler
2020-10-25 10:56:24 +09:00
parent 1858a383d0
commit 0df3bab5ef

View File

@@ -16,21 +16,6 @@ class SeleniumBrowser {
this.capabilities = Capabilities.chrome() this.capabilities = Capabilities.chrome()
this.sleep = m => new Promise(r => setTimeout(r, m)) this.sleep = m => new Promise(r => setTimeout(r, m))
this.createPool() this.createPool()
// setInterval(() => this.reCreatePool(), 1000 * 60 * 3)
}
reCreatePool() {
delete this.pool
this.pool = null
this.createPool
// this.pool.drain().then(() => {
// return this.pool.clear()
// }).catch(err => {
// logger.debug({message: err.message}, 'Pool draining error')
// return this.pool.clear()
// }).then(() => {
// this.createPool()
// })
} }
createPool() { createPool() {
@@ -57,7 +42,7 @@ class SeleniumBrowser {
}) })
} }
}, { }, {
max: 2, min: 1, testOnBorrow: true max: 20, min: 1, testOnBorrow: true
}); });
this.pool.on('factoryCreateError', function (err) { this.pool.on('factoryCreateError', function (err) {
@@ -76,7 +61,7 @@ class SeleniumBrowser {
borrowed: this.pool.borrowed, borrowed: this.pool.borrowed,
pending: this.pool.pending pending: this.pool.pending
}, 'Pool info') }, 'Pool info')
}, 5000) }, 1000 * 60 * 5)
} }
getDriver() { getDriver() {
@@ -98,13 +83,7 @@ class SeleniumBrowser {
.then(async driver => { .then(async driver => {
let html = await driver.get(uri) let html = await driver.get(uri)
.then(() => driver.findElement(By.css('body'))) .then(() => driver.findElement(By.css('body')))
.then(body => body.getAttribute('innerHTML')).catch(err => { .then(body => body.getAttribute('innerHTML'))
return false
})
if(!html) {
this.pool.release(driver)
throw new Error('Init try got Empty html')
}
let htmlPromise = this.isCaptchaPage(html) ? this.resolveCaptcha(driver) : this.getHtml(driver, html, params) let htmlPromise = this.isCaptchaPage(html) ? this.resolveCaptcha(driver) : this.getHtml(driver, html, params)
html = await htmlPromise html = await htmlPromise
this.pool.destroy(driver) this.pool.destroy(driver)