Add retries to working_docker_image?
* Also synchronize images during save
This commit is contained in:
@@ -15,9 +15,7 @@ class ExecutionEnvironmentsController < ApplicationController
|
||||
def create
|
||||
@execution_environment = ExecutionEnvironment.new(execution_environment_params)
|
||||
authorize!
|
||||
create_and_respond(object: @execution_environment) do
|
||||
sync_to_runner_management
|
||||
end
|
||||
create_and_respond(object: @execution_environment)
|
||||
end
|
||||
|
||||
def destroy
|
||||
@@ -165,9 +163,7 @@ class ExecutionEnvironmentsController < ApplicationController
|
||||
end
|
||||
|
||||
def update
|
||||
update_and_respond(object: @execution_environment, params: execution_environment_params) do
|
||||
sync_to_runner_management
|
||||
end
|
||||
update_and_respond(object: @execution_environment, params: execution_environment_params)
|
||||
end
|
||||
|
||||
def sync_all_to_runner_management
|
||||
@@ -186,11 +182,4 @@ class ExecutionEnvironmentsController < ApplicationController
|
||||
redirect_to ExecutionEnvironment, alert: t('execution_environments.index.synchronize_all.failure')
|
||||
end
|
||||
end
|
||||
|
||||
def sync_to_runner_management
|
||||
unless Runner.management_active? && Runner.strategy_class.sync_environment(@execution_environment)
|
||||
t('execution_environments.form.errors.not_synced_to_runner_management')
|
||||
end
|
||||
end
|
||||
private :sync_to_runner_management
|
||||
end
|
||||
|
@@ -79,13 +79,24 @@ class ExecutionEnvironment < ApplicationRecord
|
||||
private :validate_docker_image?
|
||||
|
||||
def working_docker_image?
|
||||
runner = Runner.for(author, self)
|
||||
output = runner.execute_command(VALIDATION_COMMAND)
|
||||
errors.add(:docker_image, "error: #{output[:stderr]}") if output[:stderr].present?
|
||||
rescue Runner::Error::NotAvailable => e
|
||||
Rails.logger.info("The Docker image could not be verified: #{e}")
|
||||
rescue Runner::Error => e
|
||||
errors.add(:docker_image, "error: #{e}")
|
||||
sync_runner_environment
|
||||
retries = 0
|
||||
begin
|
||||
runner = Runner.for(author, self)
|
||||
output = runner.execute_command(VALIDATION_COMMAND)
|
||||
errors.add(:docker_image, "error: #{output[:stderr]}") if output[:stderr].present?
|
||||
rescue Runner::Error => e
|
||||
# In case of an Runner::Error, we retry multiple times before giving up.
|
||||
# The time between each retry increases to allow the runner management to catch up.
|
||||
if retries < 5 && !Rails.env.test?
|
||||
retries += 1
|
||||
sleep retries
|
||||
retry
|
||||
elsif errors.exclude?(:docker_image)
|
||||
errors.add(:docker_image, "error: #{e}")
|
||||
raise ActiveRecord::RecordInvalid.new(self)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def delete_runner_environment
|
||||
|
Reference in New Issue
Block a user