File size: 901 Bytes
1d7d958
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { IProgressService } from '../interfaces/IProgressService';
import { ITaskQueueService } from '../interfaces/ITaskQueueService';
import { IWorkerService } from '../interfaces/IWorkerService';

export class ProgressService implements IProgressService {
  private taskQueueService: ITaskQueueService;
  private workerService: IWorkerService;

  constructor(taskQueueService: ITaskQueueService, workerService: IWorkerService) {
    this.taskQueueService = taskQueueService;
    this.workerService = workerService;
  }

  public async recordProgress(
    workerId: string,
    taskId: string,
    progress: number,
    rowsProcessed?: number,
    currentSpeed?: number
  ): Promise<void> {
    await Promise.all([
      this.taskQueueService.updateTaskProgress(taskId, progress, rowsProcessed),
      this.workerService.recordHeartbeat(workerId, taskId, rowsProcessed, currentSpeed),
    ]);
  }
}