Commit 94d5f568 authored by Alessio Caiazza's avatar Alessio Caiazza

Extract ClusterWaitForAppInstallationWorker logic into a service

parent a8d7e4bc
module Clusters
class CheckAppInstallationProgressService < BaseHelmService
def execute
return unless app.installing?
FetchAppInstallationStatusService.new(app).execute do |phase, log|
case phase
when 'Succeeded'
if app.make_installed
FinalizeAppInstallationService.new(app).execute
else
app.make_errored!("Failed to update app record; #{app.errors}")
end
when 'Failed'
app.make_errored!(log || 'Installation silently failed')
FinalizeAppInstallationService.new(app).execute
else
if Time.now.utc - app.updated_at.to_time.utc > ClusterWaitForAppInstallationWorker::TIMEOUT
app.make_errored!('App installation timeouted')
else
ClusterWaitForAppInstallationWorker.perform_in(
ClusterWaitForAppInstallationWorker::EAGER_INTERVAL, app.name, app.id)
end
end
end
end
end
end
......@@ -14,7 +14,7 @@ module Clusters
end
rescue KubeException => ke
app.make_errored!("Kubernetes error: #{ke.message}")
rescue StandardError => e
rescue StandardError
app.make_errored!("Can't start installation process")
end
end
......
......@@ -9,25 +9,7 @@ class ClusterWaitForAppInstallationWorker
def perform(app_name, app_id)
find_app(app_name, app_id) do |app|
Clusters::FetchAppInstallationStatusService.new(app).execute do |phase, log|
case phase
when 'Succeeded'
if app.make_installed
Clusters::FinalizeAppInstallationService.new(app).execute
else
app.make_errored!("Failed to update app record; #{app.errors}")
end
when 'Failed'
app.make_errored!(log || 'Installation silently failed')
Clusters::FinalizeAppInstallationService.new(app).execute
else
if Time.now.utc - app.updated_at.to_time.utc > TIMEOUT
app.make_errored!('App installation timeouted')
else
ClusterWaitForAppInstallationWorker.perform_in(EAGER_INTERVAL, app.name, app.id)
end
end
end
Clusters::CheckAppInstallationProgressService.new(app).execute
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