(workerId: number)
| 327 | } |
| 328 | |
| 329 | private async createAsyncWorker(workerId: number): Promise<void> { |
| 330 | while (true) { |
| 331 | try { |
| 332 | const workItem = await this.getNextWorkItem(workerId); |
| 333 | |
| 334 | if (workItem.job) { |
| 335 | await this.processJob(workItem.job, workerId); |
| 336 | } else if (workItem.chunk) { |
| 337 | await this.processWorkChunk(workItem.chunk, workerId); |
| 338 | } else { |
| 339 | await new Promise((resolve) => setTimeout(resolve, 1000)); |
| 340 | } |
| 341 | } catch (error) { |
| 342 | handleLog( |
| 343 | `[worker] Worker ${workerId} error: ${error instanceof Error ? error.message : String(error)}`, |
| 344 | ); |
| 345 | this.cleanupWorkerAssignment(workerId); |
| 346 | await new Promise((resolve) => setTimeout(resolve, 2000)); |
| 347 | } |
| 348 | } |
| 349 | } |
| 350 | |
| 351 | private async getNextWorkItem( |
| 352 | workerId: number, |
no test coverage detected