Welcome to mirror list, hosted at ThFree Co, Russian Federation.

trigger_schedule.rb « ci « models « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9b1dfce969a5d1d4dc2035b503238a44755f378d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
module Ci
  class TriggerSchedule < ActiveRecord::Base
    extend Ci::Model
    include Importable

    acts_as_paranoid

    belongs_to :project
    belongs_to :trigger

    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