feat: add check to see if robot is running
This commit is contained in:
@@ -15,6 +15,8 @@ interface BrowserPoolInfo {
|
|||||||
* @default false
|
* @default false
|
||||||
*/
|
*/
|
||||||
active: boolean,
|
active: boolean,
|
||||||
|
|
||||||
|
isRobotRun?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -46,17 +48,29 @@ export class BrowserPool {
|
|||||||
* @param browser remote browser instance
|
* @param browser remote browser instance
|
||||||
* @param active states if the browser's instance is being actively used
|
* @param active states if the browser's instance is being actively used
|
||||||
*/
|
*/
|
||||||
public addRemoteBrowser = (id: string, browser: RemoteBrowser, active: boolean = false): void => {
|
public addRemoteBrowser = (id: string, browser: RemoteBrowser, active: boolean = false, isRobotRun: boolean = false): void => {
|
||||||
this.pool = {
|
this.pool = {
|
||||||
...this.pool,
|
...this.pool,
|
||||||
[id]: {
|
[id]: {
|
||||||
browser,
|
browser,
|
||||||
active,
|
active,
|
||||||
|
isRobotRun
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
logger.log('debug', `Remote browser with id: ${id} added to the pool`);
|
logger.log('debug', `Remote browser with id: ${id} added to the pool`);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public hasActiveRobotRun(): boolean {
|
||||||
|
return Object.values(this.pool).some(info => info.isRobotRun);
|
||||||
|
}
|
||||||
|
|
||||||
|
public clearRobotRunState(id: string): void {
|
||||||
|
if (this.pool[id]) {
|
||||||
|
this.pool[id].isRobotRun = false;
|
||||||
|
logger.log('debug', `Robot run state cleared for browser ${id}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes the remote browser instance from the pool.
|
* Removes the remote browser instance from the pool.
|
||||||
* @param id remote browser instance's id
|
* @param id remote browser instance's id
|
||||||
@@ -67,6 +81,8 @@ export class BrowserPool {
|
|||||||
logger.log('warn', `Remote browser with id: ${id} does not exist in the pool`);
|
logger.log('warn', `Remote browser with id: ${id} does not exist in the pool`);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.clearRobotRunState(id);
|
||||||
delete (this.pool[id]);
|
delete (this.pool[id]);
|
||||||
logger.log('debug', `Remote browser with id: ${id} deleted from the pool`);
|
logger.log('debug', `Remote browser with id: ${id} deleted from the pool`);
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user