Commit 85def17c authored by Grzegorz Bizon's avatar Grzegorz Bizon

Track running shared runner builds using runtime metadata

parent 2fb3c041
......@@ -300,7 +300,7 @@ module Ci
end
# rubocop:disable CodeReuse/ServiceClass
after_transition any => [:pending] do |build, transition|
after_transition any: :pending do |build, transition|
Ci::UpdateBuildQueueService.new.push(build, transition)
build.run_after_commit do
......@@ -311,7 +311,22 @@ module Ci
after_transition pending: any do |build, transition|
Ci::UpdateBuildQueueService.new.pop(build, transition)
end
after_transition any: :running do |build, transition|
Ci::UpdateBuildQueueService.new.track(build, transition)
end
after_transition running: any do |build|
Ci::UpdateBuildQueueService.new.untrack(build, transition)
Ci::BuildRunnerSession.where(build: build).delete_all
end
# rubocop:enable CodeReuse/ServiceClass
#
after_transition pending: :running do |build|
build.ensure_metadata.update_timeout_state
end
after_transition pending: :running do |build|
build.deployment&.run
......@@ -365,14 +380,6 @@ module Ci
end
end
after_transition pending: :running do |build|
build.ensure_metadata.update_timeout_state
end
after_transition running: any do |build|
Ci::BuildRunnerSession.where(build: build).delete_all
end
after_transition any => [:skipped, :canceled] do |build, transition|
if transition.to_name == :skipped
build.deployment&.skip
......@@ -1087,6 +1094,12 @@ module Ci
::Ci::RunningBuild.where(build_id: self.id)
end
def shared_runner_build?
return false if runner.nil?
runner.instance_type?
end
protected
def run_status_commit_hooks!
......
......@@ -49,11 +49,11 @@ module Ci
end
##
# Add shared runner build tracking entry (used for queuing). This will rase
# an exception if a build has not been picked by a shared runner.
# Add shared runner build tracking entry (used for queuing).
#
def track(build, transition)
return unless Feature.enabled?(:ci_track_shared_runner_builds, build.project, default_enabled: :yaml)
return unless build.shared_runner_build?
raise InvalidQueueTransition unless transition.to == 'running'
......@@ -69,10 +69,12 @@ module Ci
end
##
# Remove a runtime build tracking entry (used for queuing).
# Remove a runtime build tracking entry for a shared runner build (used for
# queuing).
#
def untrack(build, transition)
return unless Feature.enabled?(:ci_untrack_shared_runner_builds, build.project, default_enabled: :yaml)
return unless build.shared_runner_build?
raise InvalidQueueTransition unless transition.from == 'running'
......
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