DCP: Add handling of inactivity timer
This commit is contained in:
@ -21,6 +21,9 @@ class Runner::Strategy::DockerContainerPool < Runner::Strategy
|
|||||||
|
|
||||||
def self.request_from_management(environment)
|
def self.request_from_management(environment)
|
||||||
url = "#{config[:url]}/docker_container_pool/get_container/#{environment.id}"
|
url = "#{config[:url]}/docker_container_pool/get_container/#{environment.id}"
|
||||||
|
body = {
|
||||||
|
inactivity_timeout: config[:unused_runner_expiration_time].seconds,
|
||||||
|
}
|
||||||
Rails.logger.debug { "#{Time.zone.now.getutc.inspect}: Requesting new runner at #{url}" }
|
Rails.logger.debug { "#{Time.zone.now.getutc.inspect}: Requesting new runner at #{url}" }
|
||||||
response = Faraday.post url, body
|
response = Faraday.post url, body
|
||||||
|
|
||||||
@ -71,6 +74,8 @@ class Runner::Strategy::DockerContainerPool < Runner::Strategy
|
|||||||
end
|
end
|
||||||
|
|
||||||
def attach_to_execution(command, event_loop)
|
def attach_to_execution(command, event_loop)
|
||||||
|
reset_inactivity_timer
|
||||||
|
|
||||||
@command = command
|
@command = command
|
||||||
query_params = 'logs=0&stream=1&stderr=1&stdout=1&stdin=1'
|
query_params = 'logs=0&stream=1&stderr=1&stdout=1&stdin=1'
|
||||||
websocket_url = "#{self.class.config[:ws_host]}/v1.27/containers/#{@container_id}/attach/ws?#{query_params}"
|
websocket_url = "#{self.class.config[:ws_host]}/v1.27/containers/#{@container_id}/attach/ws?#{query_params}"
|
||||||
@ -177,6 +182,19 @@ class Runner::Strategy::DockerContainerPool < Runner::Strategy
|
|||||||
@local_workspace_path ||= Pathname.new(container.binds.first.split(':').first)
|
@local_workspace_path ||= Pathname.new(container.binds.first.split(':').first)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def reset_inactivity_timer
|
||||||
|
url = "#{self.class.config[:url]}/docker_container_pool/reuse_container/#{container.id}"
|
||||||
|
body = {
|
||||||
|
inactivity_timeout: self.class.config[:unused_runner_expiration_time].seconds,
|
||||||
|
}
|
||||||
|
Rails.logger.debug { "#{Time.zone.now.getutc.inspect}: Resetting inactivity timer at #{url}" }
|
||||||
|
Faraday.post url, body
|
||||||
|
rescue Faraday::Error => e
|
||||||
|
raise Runner::Error::FaradayError.new("Request to DockerContainerPool failed: #{e.inspect}")
|
||||||
|
ensure
|
||||||
|
Rails.logger.debug { "#{Time.zone.now.getutc.inspect}: Finished resetting inactivity timer" }
|
||||||
|
end
|
||||||
|
|
||||||
class Connection < Runner::Connection
|
class Connection < Runner::Connection
|
||||||
def initialize(*args)
|
def initialize(*args)
|
||||||
@stream = 'stdout'
|
@stream = 'stdout'
|
||||||
|
Reference in New Issue
Block a user