This commit is contained in:
brow3c
2021-05-15 19:13:30 +09:00
parent b34ab575a6
commit bcd47c712c
2 changed files with 13 additions and 9 deletions

View File

@@ -14,7 +14,7 @@ class SeleniumBrowser {
let uri = params.uri let uri = params.uri
logger.info('URL %s', uri) logger.info('URL %s', uri)
if (uri.indexOf('://') > 3) { if (uri.indexOf('://') > 3) {
return this.pool.acquire() return poolingService.acquire()
.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')))

View File

@@ -12,22 +12,26 @@ class PoolingService {
browserArgs: ['--no-sandbox', '--headless', '--disable-dev-shm-usage', '--proxy-server=spiduler-tor:8118'] browserArgs: ['--no-sandbox', '--headless', '--disable-dev-shm-usage', '--proxy-server=spiduler-tor:8118']
} }
this.pool = this.createPool() this.pool = this.createPool()
this.pool.on("factoryCreateError", function (err) { }
console.log('factoryCreateError', err);
});
this.pool.on("factoryDestroyError", function (err) { acquire() {
console.log('factoryDestroyError', err); return this.pool.acquire().catch(err => this.pool.acquire())
});
} }
createPool() { createPool() {
setInterval(() => this.debugPoolStatus(), 1000 * 60 * 5) setInterval(() => this.debugPoolStatus(), 1000 * 60 * 5)
return pool.createPool({ let pool = pool.createPool({
create: () => this.create(), create: () => this.create(),
destroy: (driver) => this.destroy(driver), destroy: (driver) => this.destroy(driver),
validate: (driver) => this.validate(driver) validate: (driver) => this.validate(driver)
}, this.config.pool); }, this.config.pool);
this.pool.on("factoryCreateError", function (err) {
logger.debug({reason: err.message}, 'factoryCreateError');
});
this.pool.on("factoryDestroyError", function (err) {
logger.debug({reason: err.message}, 'factoryDestroyError');
});
return pool
} }
create() { create() {