This commit is contained in:
spiduler
2020-10-23 15:41:15 +09:00
parent 66aec216bd
commit c2866e5cb1

View File

@@ -9,6 +9,7 @@ const logger = require("logops")
class SeleniumBrowser {
constructor() {
this.config = {
browserFullCount: 0,
useHub: true, browser: 'chrome',
browserArgs: ['--no-sandbox', '--headless', '--disable-dev-shm-usage', '--proxy-server=spiduler-tor:8118']
}
@@ -34,7 +35,7 @@ class SeleniumBrowser {
})
}
}, {
max: 10, min: 1, testOnBorrow: true, acquireTimeoutMillis: 30000
max: 2, min: 1, testOnBorrow: true, acquireTimeoutMillis: 30000
});
this.pool.on('factoryCreateError', function (err) {
@@ -44,6 +45,17 @@ class SeleniumBrowser {
this.pool.on('factoryDestroyError', function (err) {
logger.error({ message: err.message }, 'pool error')
})
this.pool.use(driver => {
if(this.pool.available == 0) browserFullCount++
if(browserFullCount > 100) {
this.pool.clear()
}
return driver.getSession().then(s => driver).catch(err => {
this.pool.destroy(driver)
throw new Error('Driver session expired pool should create new instance')
})
})
}
getDriver() {