import { defineCrontabModel } from './executionModelDefinitions'; import { sequelize } from '.'; import { Model } from 'sequelize'; export class Crontab { name?: string; command: string; schedule?: string; timestamp?: string; saved?: boolean; id?: number; status?: CrontabStatus; isSystem?: 1 | 0; pid?: number; isDisabled?: 1 | 0; log_path?: string; queued_token?: string | null; isPinned?: 1 | 0; labels?: string[]; last_instance_id?: number; last_running_time?: number | null; last_execution_time?: number; sub_id?: number; extra_schedules?: Array<{ schedule: string }>; task_before?: string; task_after?: string; log_name?: string; allow_multiple_instances?: 1 | 0; skip_if_pending?: boolean; max_queue_wait?: number; catchup_seconds?: number; recovery_from?: number; work_dir?: string; constructor(options: Crontab) { this.name = options.name; this.command = options.command.trim(); this.schedule = options.schedule; this.saved = options.saved; this.id = options.id; this.status = typeof options.status === 'number' && CrontabStatus[options.status] ? options.status : CrontabStatus.idle; this.timestamp = new Date().toString(); this.isSystem = options.isSystem || 0; this.pid = options.pid; this.isDisabled = options.isDisabled || 0; this.log_path = options.log_path || ''; this.isPinned = options.isPinned || 0; this.labels = options.labels || []; this.last_running_time = options.last_running_time || 0; this.last_execution_time = options.last_execution_time || 0; this.sub_id = options.sub_id; this.extra_schedules = options.extra_schedules; this.task_before = options.task_before; this.task_after = options.task_after; this.log_name = options.log_name; this.allow_multiple_instances = options.allow_multiple_instances || 0; this.skip_if_pending = Boolean(options.skip_if_pending); this.max_queue_wait = options.max_queue_wait || 0; this.catchup_seconds = options.catchup_seconds || 0; this.recovery_from = options.recovery_from; this.work_dir = options.work_dir; } } export enum CrontabStatus { 'running' = 0, 'idle' = 1, 'disabled' = 2, 'queued' = 3, } export interface CronInstance extends Model, Crontab {} export const CrontabModel = defineCrontabModel(sequelize);