feat: add check to see if robot is running

This commit is contained in:
Rohit
2025-01-24 12:15:24 +05:30
parent e7b6788e43
commit 357488c801

View File

@@ -15,6 +15,8 @@ interface BrowserPoolInfo {
* @default false
*/
active: boolean,
isRobotRun?: boolean;
}
/**
@@ -46,17 +48,29 @@ export class BrowserPool {
* @param browser remote browser instance
* @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,
[id]: {
browser,
active,
isRobotRun
},
}
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.
* @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`);
return false;
}
this.clearRobotRunState(id);
delete (this.pool[id]);
logger.log('debug', `Remote browser with id: ${id} deleted from the pool`);
return true;