test / src /models /worker.model.ts
bipulsardar's picture
23
1d7d958
Raw History Blame Contribute Delete
1.49 kB
import { IWorker, WorkerPlatform, WorkerStatus } from '../types/worker.types';
export class WorkerModel implements IWorker {
public workerId: string;
public workerName: string;
public platform: WorkerPlatform;
public cpu: string;
public ram: string;
public gpu: string;
public tpu: string;
public batchSize: number;
public rowsPerSecond: number;
public lastHeartbeat: string;
public currentTaskId: string | null;
public status: WorkerStatus;
public tasksCompleted: number;
public tasksFailed: number;
public totalRowsProcessed: number;
public connectedAt: string;
constructor(data: Partial<IWorker> & { workerId: string; workerName: string; platform: WorkerPlatform }) {
const now = new Date().toISOString();
this.workerId = data.workerId;
this.workerName = data.workerName;
this.platform = data.platform;
this.cpu = String(data.cpu || 'Unknown');
this.ram = String(data.ram || 'Unknown');
this.gpu = String(data.gpu || 'None');
this.tpu = String(data.tpu || 'None');
this.batchSize = data.batchSize || 32;
this.rowsPerSecond = data.rowsPerSecond || 0;
this.lastHeartbeat = data.lastHeartbeat || now;
this.currentTaskId = data.currentTaskId || null;
this.status = data.status || 'idle';
this.tasksCompleted = data.tasksCompleted || 0;
this.tasksFailed = data.tasksFailed || 0;
this.totalRowsProcessed = data.totalRowsProcessed || 0;
this.connectedAt = data.connectedAt || now;
}
}