-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #36341 - Refactor ansible runner artifacts processing
- Loading branch information
1 parent
6cd18e6
commit d5df5a1
Showing
3 changed files
with
57 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
module Proxy | ||
module Ansible | ||
# Helper for Artifacts Reader | ||
class ArtifactsProcessor | ||
class << self | ||
ARTIFACTS_DIR = 'artifacts'.freeze | ||
def artifacts_reader(root) | ||
@counter ||= 1 | ||
uuid ||= if (f = Dir["#{root}/#{ARTIFACTS_DIR}/*"].first) | ||
File.basename(f) | ||
end | ||
return unless uuid | ||
|
||
job_event_dir = File.join(root, ARTIFACTS_DIR, uuid, 'job_events') | ||
all_files_with_nums = [] | ||
|
||
loop do | ||
files = Dir["#{job_event_dir}/*.json"].map do |file| | ||
num = File.basename(file)[/\A\d+/].to_i unless file.include?('partial') | ||
[file, num] | ||
end | ||
files_with_nums = files.select { |(_, num)| num && num >= @counter }.sort_by(&:last) | ||
break if files_with_nums.empty? | ||
|
||
all_files_with_nums.concat(files_with_nums) | ||
@counter = files_with_nums.last.last + 1 | ||
end | ||
all_files_with_nums | ||
end | ||
|
||
def hostname_for_event(event) | ||
hostname = event.dig('event_data', 'host') || event.dig('event_data', 'remote_addr') | ||
hostname.to_s unless hostname.nil? || hostname.empty? | ||
end | ||
|
||
def get_event_data(event, data_type) | ||
event.dig('event_data', data_type) || {} | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters