Class: Actions::Middleware::RecordSmartProxySyncHistory

Inherits:
Dynflow::Middleware
  • Object
show all
Defined in:
app/lib/actions/middleware/record_smart_proxy_sync_history.rb

Instance Method Summary collapse

Instance Method Details

#run(*args) ⇒ Object



20
21
22
23
24
25
26
27
# File 'app/lib/actions/middleware/record_smart_proxy_sync_history.rb', line 20

def run(*args)
  begin
    save_smart_proxy_sync_history
  rescue => error
    Rails.logger.error("Error saving smart proxy history: #{error.message}")
  end
  pass(*args)
end

#save_smart_proxy_sync_historyObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/lib/actions/middleware/record_smart_proxy_sync_history.rb', line 4

def save_smart_proxy_sync_history
  if (action.input[:repository_id] && (action.input[:smart_proxy_id] || action.input[:capsule_id]) && !self.action.output[:smart_proxy_history_id])
    repo_id = action.input[:repository_id]
    repo = ::Katello::Repository.find_by(id: repo_id)
    smart_proxy_id = action.input[:smart_proxy_id] || action.input[:capsule_id]
    smart_proxy = ::SmartProxy.unscoped.find_by(id: smart_proxy_id)

    if repo && smart_proxy
      self.action.output[:smart_proxy_history_id] = repo.create_smart_proxy_sync_history(smart_proxy)
    else
      fail "Smart Proxy could not be found with id #{smart_proxy_id}" if smart_proxy.nil?
      fail "Repository could not be found with id #{repo_id}" if repo.nil?
    end
  end
end