app/lib/actions/proxy_action.rb in foreman-tasks-7.0.0 vs app/lib/actions/proxy_action.rb in foreman-tasks-7.1.0

- old
+ new

@@ -20,12 +20,20 @@ def backtrace [] end end - class ProxyActionStopped; end + class ProxyActionStopped < RuntimeError + def backtrace + [] + end + end + ProxyActionStoppedEvent = ::Algebrick.type do + fields! exception: type { variants NilClass, Exception } + end + def plan(proxy, klass, options) options[:connection_options] ||= {} default_connection_options.each do |key, value| options[:connection_options][key] = value unless options[:connection_options].key?(key) end @@ -50,12 +58,12 @@ abort_proxy_task when CallbackData on_data(event.data, event.meta) when ProxyActionMissing on_proxy_action_missing - when ProxyActionStopped - on_proxy_action_stopped + when ProxyActionStoppedEvent + on_proxy_action_stopped(event) else raise "Unexpected event #{event.inspect}" end end end @@ -92,10 +100,12 @@ on_data(get_proxy_data(response)) end else suspend end + rescue RestClient::NotFound + on_proxy_action_missing end def cancel_proxy_task if output[:cancel_sent] error! ForemanTasks::Task::TaskCancelledException.new(_('Cancel enforced: the task might be still running on the proxy')) @@ -131,11 +141,15 @@ def on_proxy_action_missing error! ProxyActionMissing.new(_('Proxy task gone missing from the smart proxy')) end - def on_proxy_action_stopped - check_task_status + def on_proxy_action_stopped(event) + if event.exception + error! ProxyActionStopped.new(_('Failed to trigger task on the smart proxy: ') + event.exception.message) + else + check_task_status + end end # @override String name of an action to be triggered on server def proxy_action_name input[:proxy_action_name]