Class: Ci::PipelineSchedule

Inherits:
ApplicationRecord show all
Extended by:
Gitlab::Ci::Model
Includes:
Importable, Limitable, Schedulable, StripAttribute
Defined in:
app/models/ci/pipeline_schedule.rb

Constant Summary

Constants included from Limitable

Limitable::GLOBAL_SCOPE

Instance Attribute Summary

Attributes included from Importable

#imported, #importing

Instance Method Summary collapse

Methods included from Gitlab::Ci::Model

model_name, table_name_prefix

Methods included from Schedulable

#schedule_next_run!

Methods included from StripAttribute

#strip_attributes

Methods inherited from ApplicationRecord

at_most, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, underscore, without_order

Instance Method Details

#deactivate!Object


48
49
50
# File 'app/models/ci/pipeline_schedule.rb', line 48

def deactivate!
  update_attribute(:active, false)
end

#inactive?Boolean

Returns:

  • (Boolean)

44
45
46
# File 'app/models/ci/pipeline_schedule.rb', line 44

def inactive?
  !active?
end

#job_variablesObject


67
68
69
# File 'app/models/ci/pipeline_schedule.rb', line 67

def job_variables
  variables&.map(&:to_runner_variable) || []
end

#own!(user) ⇒ Object


40
41
42
# File 'app/models/ci/pipeline_schedule.rb', line 40

def own!(user)
  update(owner: user)
end

#owned_by?(current_user) ⇒ Boolean

Returns:

  • (Boolean)

36
37
38
# File 'app/models/ci/pipeline_schedule.rb', line 36

def owned_by?(current_user)
  owner == current_user
end

#set_next_run_atObject

The `next_run_at` column is set to the actual execution date of `PipelineScheduleWorker`. This way, a schedule like `*/1 * * * *` won't be triggered in a short interval when PipelineScheduleWorker runs irregularly by Sidekiq Memory Killer.


56
57
58
59
60
61
62
63
64
65
# File 'app/models/ci/pipeline_schedule.rb', line 56

def set_next_run_at
  now = Time.zone.now
  ideal_next_run = ideal_next_run_from(now)

  self.next_run_at = if ideal_next_run == cron_worker_next_run_from(now)
                       ideal_next_run
                     else
                       cron_worker_next_run_from(ideal_next_run)
                     end
end