From 1858a383d07addae8ce540906cdc27f94e275e3b Mon Sep 17 00:00:00 2001 From: spiduler Date: Sun, 25 Oct 2020 10:43:07 +0900 Subject: [PATCH] dsfsdf --- src/component/SeleniumBrowser.js | 34 ++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/src/component/SeleniumBrowser.js b/src/component/SeleniumBrowser.js index 4856e6e..cf4c252 100644 --- a/src/component/SeleniumBrowser.js +++ b/src/component/SeleniumBrowser.js @@ -41,15 +41,7 @@ class SeleniumBrowser { }, destroy: (driver) => { logger.info('Quitting driver') - return driver.quit().then(() => { - logger.debug({ - spare: this.pool.spareResourceCapacity, - size: this.pool.size, - available: this.pool.available, - borrowed: this.pool.borrowed, - pending: this.pool.pending - }, 'Pool info') - }).catch(err => { + return driver.quit().catch(err => { logger.debug({ message: err.message }, 'Quitting error') this.pool.release(driver) }) @@ -65,7 +57,7 @@ class SeleniumBrowser { }) } }, { - max: 10, min: 1, testOnBorrow: true + max: 2, min: 1, testOnBorrow: true }); this.pool.on('factoryCreateError', function (err) { @@ -75,6 +67,16 @@ class SeleniumBrowser { this.pool.on('factoryDestroyError', function (err) { logger.error({ message: err.message }, 'pool error') }) + + setInterval(() => { + logger.debug({ + spare: this.pool.spareResourceCapacity, + size: this.pool.size, + available: this.pool.available, + borrowed: this.pool.borrowed, + pending: this.pool.pending + }, 'Pool info') + }, 5000) } getDriver() { @@ -92,20 +94,22 @@ class SeleniumBrowser { let uri = params.uri logger.info('URL %s', uri) if (uri.indexOf('://') > 3) { - // if (this.pool) { return this.pool.acquire() .then(async driver => { let html = await driver.get(uri) .then(() => driver.findElement(By.css('body'))) - .then(body => body.getAttribute('innerHTML')) + .then(body => body.getAttribute('innerHTML')).catch(err => { + 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) html = await htmlPromise this.pool.destroy(driver) return html }) - // }else { - // throw new Error('Pool is not ready') - // } } else { throw new Error('Invalid URI - ' + uri) }