Skip to content

Commit

Permalink
Merge pull request #6272 from inspec/nm/parallel-breaking-fix
Browse files Browse the repository at this point in the history
CFINSPEC-479 Inspec parallel breaking fix
  • Loading branch information
Nik08 authored Oct 25, 2022
2 parents 7410dd7 + 4b4053c commit 44939be
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def set_example(notification, status)
control_id = notification.example.metadata[:id]
title = notification.example.metadata[:title]
set_status_mapping(control_id, status)
output_status(control_id, title) if control_ended?(control_id)
output_status(control_id, title) if control_ended?(notification, control_id)
end

def output_status(control_id, title)
Expand Down
21 changes: 13 additions & 8 deletions lib/plugins/inspec-parallel/lib/inspec-parallel/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def run
cleanup_child_processes
sleep 0.1
end
cleanup_empty_error_log_files
cleanup_daemon_process if run_in_background
end

Expand All @@ -52,6 +53,16 @@ def cleanup_daemon_process
# Calling Process.kill(9,Process.pid) kills the "stopper" process itself, rather than the one it's trying to stop.
end

def cleanup_empty_error_log_files
logs_dir_path = log_path || Dir.pwd
error_files = Dir.glob("#{logs_dir_path}/logs/*.err")
error_files.each do |error_file|
if File.exist?(error_file) && !File.size?(error_file)
File.delete(error_file)
end
end
end

def should_start_more_jobs?
@child_tracker.length < total_jobs && !invocations.empty?
end
Expand Down Expand Up @@ -107,12 +118,6 @@ def fork_another_process
rescue StandardError => e
$stderr.puts "#{Time.now.iso8601} Error Message: #{e.message}"
$stderr.puts "#{Time.now.iso8601} Error Backtrace: #{e.backtrace}"
ensure
logs_dir_path = log_path || Dir.pwd
error_file_path = File.join(logs_dir_path, "logs", "#{Process.pid}.err")
if File.exist?("#{error_file_path}") && !File.size?("#{error_file_path}")
File.delete("#{error_file_path}")
end
end

# should be unreachable but child MUST exit
Expand Down Expand Up @@ -149,11 +154,11 @@ def update_ui_poll_select(target_pid = nil)
# If we weren't provided a PID, hackishly look up the pid from the matching IO.
pid = target_pid || @child_tracker.keys.detect { |p| @child_tracker[p][:io] == pipe_ready_for_reading }
begin
while (update_line = pipe_ready_for_reading.readline) && ! pipe_ready_for_reading.closed?
while (update_line = pipe_ready_for_reading.readline) && !pipe_ready_for_reading.closed?
if update_line =~ /EOF_MARKER/
pipe_ready_for_reading.close
break
elsif update_line =~ /WARN/ || update_line =~ /ERROR/
elsif update_line =~ /WARN/ || update_line =~ /ERROR/ || update_line =~ /INFO/
create_logs(
pid,
"#{Time.now.iso8601} Extra log: #{update_line}\n"
Expand Down

0 comments on commit 44939be

Please sign in to comment.