BigW Consortium Gitlab

Return struct instead of multiple values

parent 32347415
......@@ -6,6 +6,8 @@ module Ci
attr_reader :runner
Result = Struct.new(:build, :valid?)
def initialize(runner)
@runner = runner
end
......@@ -29,10 +31,10 @@ module Ci
build.run!
end
[build, true]
Result.new(build, true)
rescue StateMachines::InvalidTransition, ActiveRecord::StaleObjectError
[nil, false]
Result.new(build, false)
end
private
......
......@@ -24,14 +24,14 @@ module Ci
new_update = current_runner.ensure_runner_queue_value
build, valid = Ci::RegisterBuildService.new(current_runner).execute
result = Ci::RegisterBuildService.new(current_runner).execute
if valid
if build
if result.valid?
if result.build
Gitlab::Metrics.add_event(:build_found,
project: build.project.path_with_namespace)
project: result.build.project.path_with_namespace)
present build, with: Entities::BuildDetails
present result.build, with: Entities::BuildDetails
else
Gitlab::Metrics.add_event(:build_not_found)
......
......@@ -171,7 +171,7 @@ module Ci
end
def execute(runner)
described_class.new(runner).execute.first
described_class.new(runner).execute.build
end
end
end
......
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