Skip to content

Commit

Permalink
Merge pull request #73 from iNecas/empty-result-handling
Browse files Browse the repository at this point in the history
Fixes #12437, refs #12288 - better handling of unexpected states
  • Loading branch information
iNecas committed Nov 12, 2015
2 parents cdba5d8 + 2f3810f commit 2ae6bb6
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 11 deletions.
17 changes: 17 additions & 0 deletions app/lib/actions/remote_execution/helpers/live_output.rb
@@ -0,0 +1,17 @@
module Actions
module RemoteExecution
module Helpers
module LiveOutput
def exception_to_output(context, exception, timestamp = Time.now)
format_output(context + ": #{exception.class} - #{exception.message}", 'debug', timestamp)
end

def format_output(message, type = 'debug', timestamp = Time.now)
{ 'output_type' => type,
'output' => message,
'timestamp' => timestamp.to_f }
end
end
end
end
end
9 changes: 8 additions & 1 deletion app/lib/actions/remote_execution/run_host_job.rb
Expand Up @@ -2,6 +2,8 @@ module Actions
module RemoteExecution
class RunHostJob < Actions::EntryAction

include Actions::RemoteExecution::Helpers::LiveOutput

def resource_locks
:link
end
Expand Down Expand Up @@ -42,7 +44,12 @@ def humanized_output
end

def live_output
planned_actions(RunProxyCommand).first.live_output
proxy_command_action = planned_actions(RunProxyCommand).first
if proxy_command_action
proxy_command_action.live_output
else
execution_plan.errors.map { |e| exception_to_output(_('Failed to initialize command'), e) }
end
end

def humanized_name
Expand Down
16 changes: 6 additions & 10 deletions app/lib/actions/remote_execution/run_proxy_command.rb
Expand Up @@ -3,6 +3,7 @@ module RemoteExecution
class RunProxyCommand < Actions::ProxyAction

include ::Dynflow::Action::Cancellable
include Actions::RemoteExecution::Helpers::LiveOutput

def plan(proxy, hostname, script, options = {})
options = { :effective_user => nil }.merge(options)
Expand Down Expand Up @@ -67,8 +68,9 @@ def current_proxy_output

def finalized_output
records = []
if self.output[:proxy_output].present?
records.concat(self.output[:proxy_output].fetch(:result, []))

if proxy_result.present?
records.concat(proxy_result)
else
records << format_output(_('No output'))
end
Expand All @@ -81,14 +83,8 @@ def finalized_output
return records
end

def exception_to_output(context, exception, timestamp = Time.now)
format_output(context + ": #{exception.class} - #{exception.message}", 'debug', timestamp)
end

def format_output(message, type = 'debug', timestamp = Time.now)
{ 'output_type' => type,
'output' => message,
'timestamp' => timestamp.to_f }
def proxy_result
self.output.fetch(:proxy_output, {}).fetch(:result, []) || []
end
end
end
Expand Down

0 comments on commit 2ae6bb6

Please sign in to comment.