All files / src/platform/workers/schemas worker.schema.ts

0% Statements 0/31
0% Branches 0/16
100% Functions 0/0
0% Lines 0/27

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77                                                                                                                                                         
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { Document, Schema as MongooseSchema } from 'mongoose';
 
@Schema({ timestamps: true, collection: 'worker_nodes' })
export class WorkerNode extends Document {
  @Prop({ required: true, unique: true, index: true })
  nodeId: string;
 
  @Prop({ required: true })
  hostname: string;
 
  @Prop({ required: true, enum: ['active', 'draining', 'offline', 'error'] })
  status: string;
 
  @Prop({ type: [String], default: [] })
  queues: string[];
 
  @Prop({ default: 10 })
  concurrency: number;
 
  @Prop({ type: Object, default: {} })
  metrics: Record<string, any>; // CPU, Memory usage
 
  @Prop({ default: null })
  lastHeartbeatAt: Date;
 
  createdAt: Date;
  updatedAt: Date;
}
export const WorkerNodeSchema = SchemaFactory.createForClass(WorkerNode);
WorkerNodeSchema.index({ status: 1, lastHeartbeatAt: 1 });
 
@Schema({ timestamps: true, collection: 'worker_jobs' })
export class WorkerJob extends Document {
  @Prop({ required: true, index: true })
  jobId: string; // BullMQ ID
 
  @Prop({ required: true, index: true })
  queueName: string;
 
  @Prop({ required: true })
  name: string; // Task/Job name
 
  @Prop({ type: MongooseSchema.Types.Mixed, default: {} })
  data: any;
 
  @Prop({
    required: true,
    enum: ['waiting', 'active', 'completed', 'failed', 'delayed', 'paused'],
  })
  status: string;
 
  @Prop({ default: null })
  assignedNodeId: string;
 
  @Prop({ default: 0 })
  progress: number;
 
  @Prop({ type: MongooseSchema.Types.Mixed, default: null })
  result: any;
 
  @Prop({ default: null })
  failedReason: string;
 
  @Prop({ default: null })
  startedAt: Date;
 
  @Prop({ default: null })
  finishedAt: Date;
 
  createdAt: Date;
  updatedAt: Date;
}
export const WorkerJobSchema = SchemaFactory.createForClass(WorkerJob);
WorkerJobSchema.index({ queueName: 1, status: 1 });
WorkerJobSchema.index({ assignedNodeId: 1 });