Add after_stage scope to commit status class

This commit is contained in:
Grzegorz Bizon 2017-02-14 11:38:19 +01:00
parent 3063ab45dd
commit 346a7c696a
3 changed files with 10 additions and 12 deletions

View file

@ -234,9 +234,7 @@ module Ci
end
def mark_as_processable_after_stage(stage_idx)
builds.skipped
.where('stage_idx > ?', stage_idx)
.find_each(&:process)
builds.skipped.after_stage(stage_idx).find_each(&:process)
end
def latest?

View file

@ -23,9 +23,6 @@ class CommitStatus < ActiveRecord::Base
where(id: max_id.group(:name, :commit_id))
end
scope :retried, -> { where.not(id: latest) }
scope :ordered, -> { order(:name) }
scope :failed_but_allowed, -> do
where(allow_failure: true, status: [:failed, :canceled])
end
@ -36,8 +33,11 @@ class CommitStatus < ActiveRecord::Base
false, all_state_names - [:failed, :canceled])
end
scope :retried, -> { where.not(id: latest) }
scope :ordered, -> { order(:name) }
scope :latest_ordered, -> { latest.ordered.includes(project: :namespace) }
scope :retried_ordered, -> { retried.ordered.includes(project: :namespace) }
scope :after_stage, -> (index) { where('stage_idx > ?', index) }
state_machine :status do
event :enqueue do

View file

@ -11,13 +11,18 @@ module Ci
# Reprocess builds in subsequent stages
#
pipeline.builds
.where('stage_idx > ?', resume_stage.index)
.after_stage(resume_stage.index)
.failed_or_canceled.find_each do |build|
Ci::RetryBuildService
.new(project, current_user)
.reprocess(build)
end
##
# Mark skipped builds as processable again
#
pipeline.mark_as_processable_after_stage(resume_stage.index)
##
# Retry builds in the first unsuccessful stage
#
@ -26,11 +31,6 @@ module Ci
.new(project, current_user)
.retry(build)
end
##
# Mark skipped builds as processable again
#
pipeline.mark_as_processable_after_stage(resume_stage.index)
end
private