Commit 6ff14634 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Improve creating builds by combining two loops

parent a76cbe52
...@@ -91,16 +91,11 @@ module Ci ...@@ -91,16 +91,11 @@ module Ci
trigger_requests.any? trigger_requests.any?
end end
def build_builds(user, trigger_request = nil, status = 'success') def build_builds(user, trigger_request = nil)
return unless config_processor return unless config_processor
## build_builds_for_stages(config_processor.stages, user,
# Note that `Array#any?` implements a short circuit evaluation, so we 'success', trigger_request)
# build builds only for the first stage that has builds available.
#
config_processor.stages.any? do |stage|
build_builds_for_stage(stage, user, status, trigger_request).present?
end
end end
def create_builds(user, trigger_request = nil) def create_builds(user, trigger_request = nil)
...@@ -122,17 +117,11 @@ module Ci ...@@ -122,17 +117,11 @@ module Ci
prior_builds = latest_builds.where.not(stage: next_stages) prior_builds = latest_builds.where.not(stage: next_stages)
prior_status = prior_builds.status prior_status = prior_builds.status
## # build builds for next stage that has builds available
# Create builds for next stages based. # and save pipeline if we have builds
# build_builds_for_stages(next_stages, build.user, prior_status,
# Note that there is a short circult evaluation here. build.trigger_request) && save
#
have_builds = next_stages.any? do |stage|
build_builds_for_stage(stage, build.user, prior_status,
build.trigger_request).present?
end
save! if have_builds
end end
def retried def retried
...@@ -179,8 +168,15 @@ module Ci ...@@ -179,8 +168,15 @@ module Ci
private private
def build_builds_for_stage(stage, user, status, trigger_request) def build_builds_for_stages(stages, user, status, trigger_request)
CreateBuildsService.new(self).execute(stage, user, status, trigger_request) ##
# Note that `Array#any?` implements a short circuit evaluation, so we
# build builds only for the first stage that has builds available.
#
stages.any? do |stage|
CreateBuildsService.new(self)
.execute(stage, user, status, trigger_request).present?
end
end end
def update_state def update_state
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment