2017-03-22 18:54:49 +00:00
|
|
|
module Ci
|
2017-03-29 11:49:47 +00:00
|
|
|
class TriggerSchedule < ActiveRecord::Base
|
2017-03-22 18:54:49 +00:00
|
|
|
extend Ci::Model
|
2017-04-04 07:55:14 +00:00
|
|
|
include Importable
|
2017-03-22 18:54:49 +00:00
|
|
|
|
|
|
|
acts_as_paranoid
|
|
|
|
|
|
|
|
belongs_to :project
|
2017-03-29 11:49:47 +00:00
|
|
|
belongs_to :trigger
|
2017-03-22 18:54:49 +00:00
|
|
|
|
2017-03-30 11:59:20 +00:00
|
|
|
delegate :ref, to: :trigger
|
|
|
|
|
2017-04-04 07:55:14 +00:00
|
|
|
validates :trigger, presence: { unless: :importing? }
|
|
|
|
validates :cron, cron: true, presence: { unless: :importing? }
|
2017-04-04 10:14:49 +00:00
|
|
|
validates :cron_time_zone, cron_time_zone: true, presence: { unless: :importing? }
|
2017-04-04 07:55:14 +00:00
|
|
|
validates :ref, presence: { unless: :importing? }
|
2017-03-29 18:33:23 +00:00
|
|
|
|
|
|
|
after_create :schedule_next_run!
|
|
|
|
|
2017-03-22 18:54:49 +00:00
|
|
|
def schedule_next_run!
|
2017-04-04 09:44:25 +00:00
|
|
|
next_time = Gitlab::Ci::CronParser.new(cron, cron_time_zone).next_time_from(Time.now)
|
2017-04-04 07:58:02 +00:00
|
|
|
update!(next_run_at: next_time) if next_time.present?
|
2017-03-22 18:54:49 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|