import { Entity, Column } from 'typeorm'; import { Expose } from 'class-transformer'; import { BaseEntity } from '../../meta/entity/base-entity.entity'; import { WORKFLOW_EXECUTION_LOG } from '../constants/schedule.constants'; /** * WorkflowExecutionLog Entity * Tracks every execution of a scheduled workflow */ @Entity({ name: 'frm_wf_execution_log' }) export class WorkflowExecutionLog extends BaseEntity { constructor() { super(); this.entity_type = WORKFLOW_EXECUTION_LOG; } /** * Reference to the scheduled workflow */ @Column({ type: 'bigint', nullable: false }) @Expose() schedule_id: number; /** * Reference to the workflow being executed */ @Column({ type: 'bigint', nullable: false }) @Expose() workflow_id: number; /** * Bull job ID for this execution */ @Column({ type: 'varchar', length: 255, nullable: true }) @Expose() job_id: string; /** * Execution status: PENDING, RUNNING, COMPLETED, FAILED, PARTIAL */ @Column({ type: 'varchar', length: 50, nullable: false, default: 'PENDING' }) @Expose() execution_status: string; /** * When the execution started */ @Column({ type: 'timestamp', nullable: true }) @Expose() started_at: Date; /** * When the execution completed */ @Column({ type: 'timestamp', nullable: true }) @Expose() completed_at: Date; /** * Duration of execution in milliseconds */ @Column({ type: 'int', nullable: true }) @Expose() duration_ms: number; /** * How the execution was triggered: SCHEDULE or MANUAL */ @Column({ type: 'varchar', length: 50, nullable: false, default: 'SCHEDULE' }) @Expose() triggered_by: string; /** * User ID who triggered manual execution (if applicable) */ @Column({ type: 'bigint', nullable: true }) @Expose() triggered_by_user_id: number | null; /** * Total number of records processed */ @Column({ type: 'int', nullable: false, default: 0 }) @Expose() total_records: number; /** * Number of successfully processed records */ @Column({ type: 'int', nullable: false, default: 0 }) @Expose() successful_records: number; /** * Number of failed records */ @Column({ type: 'int', nullable: false, default: 0 }) @Expose() failed_records: number; /** * Current retry attempt number */ @Column({ type: 'int', nullable: false, default: 0 }) @Expose() retry_count: number; /** * Maximum retry attempts allowed */ @Column({ type: 'int', nullable: false, default: 3 }) @Expose() max_retries: number; /** * Error message if execution failed */ @Column({ type: 'text', nullable: true }) @Expose() error_message: string; /** * Detailed error stack trace */ @Column({ type: 'text', nullable: true }) @Expose() error_stack: string; /** * Execution results and details in JSON format */ @Column({ type: 'json', nullable: true }) @Expose() execution_details: { batchesProcessed?: number; actionsExecuted?: Array<{ actionType: string; success: boolean; recordsAffected?: number; error?: string; }>; errors?: Array<{ recordId?: number; error: string; }>; }; /** * Additional metadata for this execution */ @Column({ type: 'json', nullable: true }) @Expose() metadata: Record; }