diff options
author | Z.J. van de Weg <git@zjvandeweg.nl> | 2017-04-14 11:01:02 +0200 |
---|---|---|
committer | Z.J. van de Weg <git@zjvandeweg.nl> | 2017-04-19 21:04:54 +0200 |
commit | 46386a30dbb0cc2d45df54f86e434f191fb7a790 (patch) | |
tree | b96729bdc0ef9d5c7b9fee1d6d867df6d8a476fe /app/models/ci/trigger_schedule.rb | |
parent | c57e66bebb930b1a7be539a809f7f5a8188e9870 (diff) | |
download | gitlab-ce-46386a30dbb0cc2d45df54f86e434f191fb7a790.tar.gz |
WIP
Diffstat (limited to 'app/models/ci/trigger_schedule.rb')
-rw-r--r-- | app/models/ci/trigger_schedule.rb | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/app/models/ci/trigger_schedule.rb b/app/models/ci/trigger_schedule.rb index 012a18eb439..454c73ca9be 100644 --- a/app/models/ci/trigger_schedule.rb +++ b/app/models/ci/trigger_schedule.rb @@ -12,19 +12,31 @@ module Ci validates :cron, unless: :importing_or_inactive?, cron: true, presence: { unless: :importing_or_inactive? } validates :cron_timezone, cron_timezone: true, presence: { unless: :importing_or_inactive? } validates :ref, presence: { unless: :importing_or_inactive? } + validates :description, presence: true before_save :set_next_run_at scope :active, -> { where(active: true) } + scope :inactive, -> { where(active: false) } def importing_or_inactive? importing? || !active? end + def inactive? + !active? + end + def set_next_run_at self.next_run_at = Gitlab::Ci::CronParser.new(cron, cron_timezone).next_time_from(Time.now) end + def schedule_first_run! + if next_run_at < real_next_run + #TODO create a schedule service to be used here and in the worker + end + end + def schedule_next_run! save! # with set_next_run_at rescue ActiveRecord::RecordInvalid |