test / src /models /task.model.ts
bipulsardar's picture
23
1d7d958
Raw History Blame Contribute Delete
1.4 kB
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 };
}
}