diff options
Diffstat (limited to 'app/models/commit_status.rb')
-rw-r--r-- | app/models/commit_status.rb | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/app/models/commit_status.rb b/app/models/commit_status.rb index 7e99f128dad..475f82f23ca 100644 --- a/app/models/commit_status.rb +++ b/app/models/commit_status.rb @@ -14,6 +14,10 @@ class CommitStatus < ApplicationRecord belongs_to :pipeline, class_name: 'Ci::Pipeline', foreign_key: :commit_id belongs_to :auto_canceled_by, class_name: 'Ci::Pipeline' + has_many :needs, class_name: 'Ci::BuildNeed', foreign_key: :build_id, inverse_of: :build + + enum scheduling_type: { stage: 0, dag: 1 }, _prefix: true + delegate :commit, to: :pipeline delegate :sha, :short_sha, :before_sha, to: :pipeline @@ -90,7 +94,12 @@ class CommitStatus < ApplicationRecord end before_save if: :status_changed?, unless: :importing? do - if Feature.disabled?(:ci_atomic_processing, project) + # we mark `processed` as always changed: + # another process might change its value and our object + # will not be refreshed to pick the change + self.processed_will_change! + + if !::Gitlab::Ci::Features.atomic_processing?(project) self.processed = nil elsif latest? self.processed = false # force refresh of all dependent ones @@ -132,15 +141,15 @@ class CommitStatus < ApplicationRecord end before_transition [:created, :waiting_for_resource, :preparing, :skipped, :manual, :scheduled] => :pending do |commit_status| - commit_status.queued_at = Time.now + commit_status.queued_at = Time.current end before_transition [:created, :preparing, :pending] => :running do |commit_status| - commit_status.started_at = Time.now + commit_status.started_at = Time.current end before_transition any => [:success, :failed, :canceled] do |commit_status| - commit_status.finished_at = Time.now + commit_status.finished_at = Time.current end before_transition any => :failed do |commit_status, transition| @@ -185,8 +194,10 @@ class CommitStatus < ApplicationRecord end def self.update_as_processed! - # Marks items as processed, and increases `lock_version` (Optimisitc Locking) - update_all('processed=TRUE, lock_version=COALESCE(lock_version,0)+1') + # Marks items as processed + # we do not increase `lock_version`, as we are the one + # holding given lock_version (Optimisitc Locking) + update_all(processed: true) end def self.locking_enabled? @@ -276,7 +287,7 @@ class CommitStatus < ApplicationRecord end def schedule_stage_and_pipeline_update - if Feature.enabled?(:ci_atomic_processing, project) + if ::Gitlab::Ci::Features.atomic_processing?(project) # Atomic Processing requires only single Worker PipelineProcessWorker.perform_async(pipeline_id, [id]) else |