Skip to content
Snippets Groups Projects

Resolve "Run CI/CD pipelines on a schedule" - "Basic backend implementation"

12 files
+ 56
49
Compare changes
  • Side-by-side
  • Inline
Files
12
@@ -12,13 +12,13 @@ class TriggerSchedule < ActiveRecord::Base
@@ -12,13 +12,13 @@ class TriggerSchedule < ActiveRecord::Base
validates :trigger, presence: { unless: :importing? }
validates :trigger, presence: { unless: :importing? }
validates :cron, cron: true, presence: { unless: :importing? }
validates :cron, cron: true, presence: { unless: :importing? }
validates :cron_time_zone, cron_time_zone: true, presence: { unless: :importing? }
validates :cron_timezone, cron_timezone: true, presence: { unless: :importing? }
validates :ref, presence: { unless: :importing? }
validates :ref, presence: { unless: :importing? }
after_create :schedule_next_run!
after_create :schedule_next_run!
def schedule_next_run!
def schedule_next_run!
next_time = Gitlab::Ci::CronParser.new(cron, cron_time_zone).next_time_from(Time.now)
next_time = Gitlab::Ci::CronParser.new(cron, cron_timezone).next_time_from(Time.now)
update!(next_run_at: next_time) if next_time.present?
update!(next_run_at: next_time) if next_time.present?
end
end
end
end
Loading