File size: 1,395 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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { ITask, TaskStatus } from '../types/task.types';

export class TaskModel implements ITask {
  public taskId: string;
  public startRow: number;
  public endRow: number;
  public startOffset?: number;
  public endOffset?: number;
  public workerId: string | null;
  public status: TaskStatus;
  public retries: number;
  public progress: number;
  public rowsProcessed?: number;
  public leaseUntil: string | null;
  public createdAt: string;
  public updatedAt: string;
  public completedAt: string | null;
  public errorMessage?: string | null;

  constructor(data: Partial<ITask> & { taskId: string; startRow: number; endRow: number }) {
    const now = new Date().toISOString();
    this.taskId = data.taskId;
    this.startRow = data.startRow;
    this.endRow = data.endRow;
    this.startOffset = data.startOffset;
    this.endOffset = data.endOffset;
    this.workerId = data.workerId || null;
    this.status = data.status || 'pending';
    this.retries = data.retries || 0;
    this.progress = data.progress || 0;
    this.rowsProcessed = data.rowsProcessed || 0;
    this.leaseUntil = data.leaseUntil || null;
    this.createdAt = data.createdAt || now;
    this.updatedAt = data.updatedAt || now;
    this.completedAt = data.completedAt || null;
    this.errorMessage = data.errorMessage || null;
  }

  public static toJSON(task: ITask): ITask {
    return { ...task };
  }
}