import { Entity, Column } from 'typeorm'; import { Expose } from 'class-transformer'; import { BaseEntity } from '../../meta/entity/base-entity.entity'; import { SCHEDULED_WORKFLOW } from '../constants/schedule.constants'; /** * ScheduledWorkflow Entity * Represents a workflow that is scheduled to run at specific times */ @Entity({ name: 'frm_wf_scheduled_workflow' }) export class ScheduledWorkflow extends BaseEntity { constructor() { super(); this.entity_type = SCHEDULED_WORKFLOW; } /** * Reference to the workflow that will be executed */ @Column({ type: 'bigint', nullable: false }) @Expose() workflow_id: number; /** * Workflow name for quick reference */ @Column({ type: 'varchar', length: 255, nullable: true }) @Expose() workflow_name: string; /** * Description of the scheduled workflow */ @Column({ type: 'text', nullable: true }) @Expose() description: string; /** * Cron expression defining the schedule * Example: "0 9 * * 1-5" (Every weekday at 9 AM) */ @Column({ type: 'varchar', length: 255, nullable: false }) @Expose() cron_expression: string; /** * Timezone for the schedule (IANA timezone format) * Example: "Asia/Kolkata", "America/New_York" */ @Column({ type: 'varchar', length: 100, nullable: false, default: 'Asia/Kolkata' }) @Expose() timezone: string; /** * Schedule start date (optional) */ @Column({ type: 'timestamp', nullable: true }) @Expose() start_date: Date | null; /** * Schedule end date (optional) */ @Column({ type: 'timestamp', nullable: true }) @Expose() end_date: Date | null; /** * Maximum number of executions allowed (optional) */ @Column({ type: 'int', nullable: true }) @Expose() max_executions: number; /** * Current execution count */ @Column({ type: 'int', nullable: false, default: 0 }) @Expose() execution_count: number; /** * Last execution timestamp */ @Column({ type: 'timestamp', nullable: true }) @Expose() last_execution_at: Date | null; /** * Next scheduled execution timestamp */ @Column({ type: 'timestamp', nullable: true }) @Expose() next_execution_at: Date | null; /** * Schedule status: ACTIVE, PAUSED, INACTIVE, EXPIRED */ @Column({ type: 'varchar', length: 50, nullable: false, default: 'ACTIVE' }) @Expose() schedule_status: string; /** * Bull job ID for tracking */ @Column({ type: 'varchar', length: 255, nullable: true }) @Expose() job_id: string | null; /** * Retry configuration in JSON format * Example: {"maxRetries": 3, "retryDelay": 5000, "backoffMultiplier": 2} */ @Column({ type: 'json', nullable: true }) @Expose() retry_config: { maxRetries: number; retryDelay: number; backoffMultiplier: number; }; /** * Actions to be performed when workflow executes * Array of action configurations */ @Column({ type: 'json', nullable: true }) @Expose() actions: Array<{ actionType: string; actionConfig: Record; targetEntityType?: string; filterCriteria?: Record; }>; /** * Additional metadata for the schedule */ @Column({ type: 'json', nullable: true }) @Expose() metadata: Record; /** * Whether this schedule is enabled */ @Column({ type: 'boolean', nullable: false, default: true }) @Expose() is_enabled: boolean; }