mirror of
https://github.com/TheNetsky/Microsoft-Rewards-Script.git
synced 2026-01-27 10:21:03 +00:00
fix: workers not exiting when using mutliple clusters (#435)
* fix: workers not exiting when using mutliple clusters * refactor: use process.disconnect for cleaner exit
This commit is contained in:
@@ -87,6 +87,7 @@ export class MicrosoftRewardsBot {
|
|||||||
private pointsCanCollect = 0
|
private pointsCanCollect = 0
|
||||||
|
|
||||||
private activeWorkers: number
|
private activeWorkers: number
|
||||||
|
private exitedWorkers: number[]
|
||||||
private browserFactory: Browser = new Browser(this)
|
private browserFactory: Browser = new Browser(this)
|
||||||
private accounts: Account[]
|
private accounts: Account[]
|
||||||
private workers: Workers
|
private workers: Workers
|
||||||
@@ -115,6 +116,7 @@ export class MicrosoftRewardsBot {
|
|||||||
}
|
}
|
||||||
this.config = loadConfig()
|
this.config = loadConfig()
|
||||||
this.activeWorkers = this.config.clusters
|
this.activeWorkers = this.config.clusters
|
||||||
|
this.exitedWorkers = []
|
||||||
}
|
}
|
||||||
|
|
||||||
get isMobile(): boolean {
|
get isMobile(): boolean {
|
||||||
@@ -182,6 +184,11 @@ export class MicrosoftRewardsBot {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const onWorkerDone = async (label: 'exit' | 'disconnect', worker: Worker, code?: number): Promise<void> => {
|
const onWorkerDone = async (label: 'exit' | 'disconnect', worker: Worker, code?: number): Promise<void> => {
|
||||||
|
const { pid } = worker.process
|
||||||
|
|
||||||
|
if (!pid || this.exitedWorkers.includes(pid)) return
|
||||||
|
else this.exitedWorkers.push(pid)
|
||||||
|
|
||||||
this.activeWorkers -= 1
|
this.activeWorkers -= 1
|
||||||
this.logger.warn(
|
this.logger.warn(
|
||||||
'main',
|
'main',
|
||||||
@@ -226,6 +233,7 @@ export class MicrosoftRewardsBot {
|
|||||||
if (process.send) {
|
if (process.send) {
|
||||||
process.send({ __stats: stats })
|
process.send({ __stats: stats })
|
||||||
}
|
}
|
||||||
|
process.disconnect()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.logger.error(
|
this.logger.error(
|
||||||
'main',
|
'main',
|
||||||
|
|||||||
Reference in New Issue
Block a user