Skip to content

Commit

Permalink
Merge pull request #183 from smortex/182
Browse files Browse the repository at this point in the history
(#182) Report failure with exit code in mco tasks
  • Loading branch information
ripienaar authored Jul 5, 2022
2 parents 3b0c035 + 5b8c269 commit 8f873e6
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions lib/mcollective/application/tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,9 @@ def run_command
Util.colorize(:bold, bolt_tasks.ddl.meta[:timeout])
])

request_and_report(:run_and_wait, request)
success = request_and_report(:run_and_wait, request)

exit(success ? 0 : 1)
end
ensure
reset_client!
Expand Down Expand Up @@ -273,11 +275,15 @@ def status_command
else
say("Requesting task status for request %s, showing failures only pass --verbose for all output" % Util.colorize(:bold, taskid)) unless options[:verbose]

request_and_report(:task_status, {:task_id => taskid}, taskid)
success = request_and_report(:task_status, {:task_id => taskid}, taskid)

exit(success ? 0 : 1)
end
end

def request_and_report(action, arguments, taskid=nil) # rubocop:disable Metrics/MethodLength
res = true

task_not_known_nodes = 0
wrapper_failure = 0
completed_nodes = 0
Expand All @@ -302,16 +308,24 @@ def request_and_report(action, arguments, taskid=nil) # rubocop:disable Metrics/
status = reply[:data]

if reply[:statuscode] == 3
res = false
fail_nodes += 1
task_not_known_nodes += 1
elsif [-1, 0].include?(status[:exitcode])
status[:completed] ? completed_nodes += 1 : running_nodes += 1
runtime += status[:runtime]
reply[:statuscode] == 0 ? success_nodes += 1 : fail_nodes += 1
if reply[:statuscode] == 0
success_nodes += 1
else
res = false
fail_nodes += 1
end
elsif reply[:statuscode] == 5
res = false
wrapper_failure += 1
fail_nodes += 1
else
res = false
fail_nodes += 1
end

Expand Down Expand Up @@ -351,6 +365,8 @@ def request_and_report(action, arguments, taskid=nil) # rubocop:disable Metrics/
runtime,
bolt_tasks.stats
)

res
ensure
reset_client!
end
Expand Down

0 comments on commit 8f873e6

Please sign in to comment.