Class: Actions::ForemanOpenbolt::CleanupProxyArtifacts

Inherits:
EntryAction
  • Object
show all
Defined in:
app/lib/actions/foreman_openbolt/cleanup_proxy_artifacts.rb

Instance Method Summary collapse

Instance Method Details

#humanized_inputObject



35
36
37
38
# File 'app/lib/actions/foreman_openbolt/cleanup_proxy_artifacts.rb', line 35

def humanized_input
  proxy_name = ::SmartProxy.find_by(id: input[:proxy_id])&.name || '(unknown)'
  "job #{input[:job_id]} on #{proxy_name}"
end

#humanized_nameObject



31
32
33
# File 'app/lib/actions/foreman_openbolt/cleanup_proxy_artifacts.rb', line 31

def humanized_name
  _("Cleanup OpenBolt task artifacts")
end

#plan(proxy_id, job_id) ⇒ Object



6
7
8
# File 'app/lib/actions/foreman_openbolt/cleanup_proxy_artifacts.rb', line 6

def plan(proxy_id, job_id)
  plan_self(proxy_id: proxy_id, job_id: job_id)
end

#rescue_strategyObject



26
27
28
29
# File 'app/lib/actions/foreman_openbolt/cleanup_proxy_artifacts.rb', line 26

def rescue_strategy
  # Skip rescue - if cleanup fails, we don't want to retry
  Dynflow::Action::Rescue::Skip
end

#runObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/lib/actions/foreman_openbolt/cleanup_proxy_artifacts.rb', line 10

def run
  proxy = ::SmartProxy.find_by(id: input[:proxy_id])
  unless proxy
    Rails.logger.warn("Proxy #{input[:proxy_id]} not found during cleanup for job #{input[:job_id]}, skipping")
    return
  end

  api = ::ProxyAPI::Openbolt.new(url: proxy.url)
  response = api.delete_job_artifacts(job_id: input[:job_id])
  Rails.logger.debug { "Cleaned up artifacts for job #{input[:job_id]} on proxy #{proxy.name}: #{response}" }
rescue StandardError => e
  # Don't fail the action if cleanup fails - it's not critical
  Rails.logger.error("Failed to cleanup artifacts for job #{input[:job_id]}: #{e.class}: #{e.message}")
  Rails.logger.error(e.backtrace.join("\n")) if e.backtrace
end