import { Column, CreateDateColumn, Entity, Index, PrimaryGeneratedColumn, } from 'typeorm'; /** * سجل تنفيذ المهام الدورية (O5). * * الجدول: `tripz_job_executions`. * * كل صف = تنفيذ واحد لأي مهمة كانت (sweeper, bot, report...). * الهدف: إظهار آخر نجاح/فشل لكل مهمة + مدة التنفيذ + سبب الفشل. * لا مهمة صامتة — كل تنفيذ يُسجَّل هنا. */ @Entity('job_executions') @Index(['job_name', 'started_at']) export class JobExecution { @PrimaryGeneratedColumn('uuid') id: string; /** اسم المهمة (cron:scheduled_trips_sweep, cron:surge_recalculate...). */ @Column() job_name: string; /** حالة التنفيذ. */ @Column({ type: 'varchar', length: 20 }) status: 'running' | 'success' | 'failed' | 'timeout'; /** لحظة بدء التنفيذ الفعلي (لا وقت إضاف الطور). */ @Column({ type: 'timestamptz' }) started_at: Date; /** لحظة انتهاء التنفيذ. */ @Column({ type: 'timestamptz', nullable: true }) finished_at: Date | null; /** مدة التنفيذ بالميلي ثانية. */ @Column({ type: 'int', nullable: true }) duration_ms: number; /** عدد العناصر التي عالجتها المهمة (مثلاً: عدد الرحلات التي انتهت). */ @Column({ type: 'int', default: 0 }) items_processed: number; /** رسالة خطأ (فقط عند الفشل). */ @Column({ type: 'text', nullable: true }) error_message: string | null; /** معرّف المستأجر (إن كانت المهمة خاصة بمستأجر). */ @Column({ type: 'uuid', nullable: true }) tenant_id: string | null; @CreateDateColumn() created_at: Date; }