app/models/scheduled_task.rb in tasks_scheduler-0.2.3 vs app/models/scheduled_task.rb in tasks_scheduler-0.3.0

- old
+ new

@@ -35,13 +35,15 @@ STATUS_DISABLED = 'disabled' LAST_FAIL_STATUSES = [STATUS_FAILED, STATUS_ABORTED, STATUS_TIMEOUT] validates :scheduling, presence: true, 'tasks_scheduler/cron_scheduling': true - validates :task, presence: true, inclusion: { in: rake_tasks } + validates :task, presence: true validates :last_fail_status, allow_blank: true, inclusion: { in: LAST_FAIL_STATUSES } + validate :validate_task + LOG_RUNNING = 'running' LOG_SUCCESSFUL = 'successful' LOG_UNSUCCESSFUL = 'unsuccessful' def cron_parser @@ -73,7 +75,18 @@ raise "No permission to query #{pid}!" rescue Errno::ESRCH return false rescue raise "Unable to determine status for #{pid}" + end + + def task_exist? + self.class.rake_tasks.include?(task) + end + + def validate_task + return if task.blank? + return unless task_changed? + return if self.class.rake_tasks.include?(task) + errors.add(:task, "Task \"#{task}\" not found") end end