gitlab-org--gitlab-foss/app/models/ci/trigger_schedule.rb

26 lines
706 B
Ruby
Raw Normal View History

module Ci
class TriggerSchedule < ActiveRecord::Base
extend Ci::Model
include Importable
acts_as_paranoid
belongs_to :project
belongs_to :trigger
2017-03-30 11:59:20 +00:00
delegate :ref, to: :trigger
validates :trigger, presence: { unless: :importing? }
validates :cron, cron: true, presence: { unless: :importing? }
validates :cron_time_zone, cron_time_zone: true, presence: { unless: :importing? }
validates :ref, presence: { unless: :importing? }
after_create :schedule_next_run!
def schedule_next_run!
next_time = Gitlab::Ci::CronParser.new(cron, cron_time_zone).next_time_from(Time.now)
update!(next_run_at: next_time) if next_time.present?
end
end
end