d0b8f536a1
This removes all usage of soft removals except for the "pending delete" system implemented for projects. This in turn simplifies all the query plans of the models that used soft removals. Since we don't really use soft removals for anything useful there's no point in keeping it around. This _does_ mean that hard removals of issues (which only admins can do if I'm not mistaken) can influence the "iid" values, but that code is broken to begin with. More on this (and how to fix it) can be found in https://gitlab.com/gitlab-org/gitlab-ce/issues/31114. Fixes https://gitlab.com/gitlab-org/gitlab-ce/issues/37447
65 lines
1.8 KiB
Ruby
65 lines
1.8 KiB
Ruby
module Ci
|
|
class PipelineSchedule < ActiveRecord::Base
|
|
extend Gitlab::Ci::Model
|
|
include Importable
|
|
include IgnorableColumn
|
|
|
|
ignore_column :deleted_at
|
|
|
|
belongs_to :project
|
|
belongs_to :owner, class_name: 'User'
|
|
has_one :last_pipeline, -> { order(id: :desc) }, class_name: 'Ci::Pipeline'
|
|
has_many :pipelines
|
|
has_many :variables, class_name: 'Ci::PipelineScheduleVariable', validate: false
|
|
|
|
validates :cron, unless: :importing?, cron: true, presence: { unless: :importing? }
|
|
validates :cron_timezone, cron_timezone: true, presence: { unless: :importing? }
|
|
validates :ref, presence: { unless: :importing? }
|
|
validates :description, presence: true
|
|
validates :variables, variable_duplicates: true
|
|
|
|
before_save :set_next_run_at
|
|
|
|
scope :active, -> { where(active: true) }
|
|
scope :inactive, -> { where(active: false) }
|
|
|
|
accepts_nested_attributes_for :variables, allow_destroy: true
|
|
|
|
def owned_by?(current_user)
|
|
owner == current_user
|
|
end
|
|
|
|
def own!(user)
|
|
update(owner: user)
|
|
end
|
|
|
|
def inactive?
|
|
!active?
|
|
end
|
|
|
|
def deactivate!
|
|
update_attribute(:active, false)
|
|
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_next_run!
|
|
save! # with set_next_run_at
|
|
rescue ActiveRecord::RecordInvalid
|
|
update_attribute(:next_run_at, nil) # update without validation
|
|
end
|
|
|
|
def real_next_run(
|
|
worker_cron: Settings.cron_jobs['pipeline_schedule_worker']['cron'],
|
|
worker_time_zone: Time.zone.name)
|
|
Gitlab::Ci::CronParser.new(worker_cron, worker_time_zone)
|
|
.next_time_from(next_run_at)
|
|
end
|
|
|
|
def job_variables
|
|
variables&.map(&:to_runner_variable) || []
|
|
end
|
|
end
|
|
end
|