Skip to content

Commit 6455a38

Browse files
committed
Version 1.1.2
1 parent bbbe384 commit 6455a38

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@hoplin/puppeteer-pool",
3-
"version": "1.1.1",
3+
"version": "1.1.2",
44
"main": "dist/index.js",
55
"description": "Puppeteer Pool Manager for worker server, process daemon, commands etc...",
66
"repository": "https://github.com/J-Hoplin/Puppeteer-Pool.git",

src/manager.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ export type PoolMetricsType = {
2828
SessionPoolCount: number;
2929
};
3030

31+
enum SessionPoolManagerState {
32+
LIVE = 'LIVE',
33+
PENDING = 'PENDING',
34+
DOWN = 'DOWN',
35+
}
36+
3137
/**
3238
* Global Instances
3339
*/
@@ -512,6 +518,9 @@ class PuppeteerCapsule {
512518
*
513519
*/
514520
class SessionPoolManager<T = unknown> {
521+
// State of session pool manager
522+
private state: SessionPoolManagerState = SessionPoolManagerState.LIVE;
523+
515524
constructor(
516525
private poolId: number,
517526
private browser: PuppeteerCapsule,
@@ -529,13 +538,26 @@ class SessionPoolManager<T = unknown> {
529538
return await this.pool.release(session);
530539
}
531540

532-
async close() {
541+
// Do not use JS getter, setter
542+
public getState() {
543+
return this.state;
544+
}
545+
546+
private setState(state: SessionPoolManagerState) {
547+
this.state = state;
548+
}
549+
550+
public async close() {
533551
await this.pool.drain();
534552
await this.pool.clear();
535553
await this.browser.closeBrowser();
536554
}
537555

538556
async rebootSessionPoolPuppeteer() {
557+
if (this.state !== SessionPoolManagerState.LIVE) {
558+
return;
559+
}
560+
this.setState(SessionPoolManagerState.PENDING);
539561
// Wait until all session is released
540562
while (this.pool.borrowed >= 1) {
541563
await new Promise((resolve) => setTimeout(resolve, 50));
@@ -556,6 +578,7 @@ class SessionPoolManager<T = unknown> {
556578
logger.info(
557579
`Reboot session pool --- PID: ${browserProcessId} --- Pool ID: ${this.poolId}`,
558580
);
581+
this.setState(SessionPoolManagerState.LIVE);
559582
return browserProcessId;
560583
}
561584
}

0 commit comments

Comments
 (0)