Class: Ci::PipelineSchedule

Inherits:
ApplicationRecord show all
Extended by:
Gitlab::Utils::Override
Includes:
BatchNullifyDependentAssociations, CronSchedulable, EachBatch, Importable, Limitable, StripAttribute
Defined in:
app/models/ci/pipeline_schedule.rb

Constant Summary

Constants included from Limitable

Limitable::GLOBAL_SCOPE

Constants inherited from ApplicationRecord

ApplicationRecord::MAX_PLUCK

Constants included from ResetOnUnionError

ResetOnUnionError::MAX_RESET_PERIOD

Instance Attribute Summary

Attributes included from Importable

#imported, #importing

Instance Method Summary collapse

Methods included from Gitlab::Utils::Override

extended, extensions, included, method_added, override, prepended, queue_verification, verify!

Methods included from BatchNullifyDependentAssociations

#nullify_dependent_associations_in_batches

Methods included from Limitable

#exceeds_limits?

Methods included from Schedulable

#schedule_next_run!

Methods included from StripAttribute

#strip_attributes!

Methods inherited from ApplicationRecord

model_name, table_name_prefix

Methods inherited from ApplicationRecord

cached_column_list, #create_or_load_association, declarative_enum, default_select_columns, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, #readable_by?, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, #to_ability_name, underscore, where_exists, where_not_exists, with_fast_read_statement_timeout, without_order

Methods included from SensitiveSerializableHash

#serializable_hash

Instance Method Details

#daily_limitObject



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

def daily_limit
  project.actual_limits.limit_for(:ci_daily_pipeline_schedule_triggers)
end

#deactivate!Object



51
52
53
# File 'app/models/ci/pipeline_schedule.rb', line 51

def deactivate!
  update_attribute(:active, false)
end

#destroyObject

Using destroy instead of before_destroy as we want nullify_dependent_associations_in_batches to run first and not in a transaction block. This prevents timeouts for schedules with numerous pipelines



88
89
90
91
92
# File 'app/models/ci/pipeline_schedule.rb', line 88

def destroy
  nullify_dependent_associations_in_batches

  super
end

#for_tag?Boolean

Returns:

  • (Boolean)


76
77
78
79
80
# File 'app/models/ci/pipeline_schedule.rb', line 76

def for_tag?
  return false unless ref.present?

  ref.start_with? 'refs/tags/'
end

#inactive?Boolean

Returns:

  • (Boolean)


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

def inactive?
  !active?
end

#job_variablesObject



55
56
57
# File 'app/models/ci/pipeline_schedule.rb', line 55

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

#own!(user) ⇒ Object



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

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

#owned_by?(current_user) ⇒ Boolean

Returns:

  • (Boolean)


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

def owned_by?(current_user)
  owner == current_user
end

#ref_for_displayObject



70
71
72
73
74
# File 'app/models/ci/pipeline_schedule.rb', line 70

def ref_for_display
  return unless ref.present?

  ref.gsub(%r{^refs/(heads|tags)/}, '')
end

#set_next_run_atObject



60
61
62
63
64
# File 'app/models/ci/pipeline_schedule.rb', line 60

def set_next_run_at
  self.next_run_at = ::Ci::PipelineSchedules::CalculateNextRunService # rubocop: disable CodeReuse/ServiceClass
                       .new(project)
                       .execute(self, fallback_method: method(:calculate_next_run_at))
end

#worker_cron_expressionObject



82
83
84
# File 'app/models/ci/pipeline_schedule.rb', line 82

def worker_cron_expression
  Settings.cron_jobs['pipeline_schedule_worker']['cron']
end