Skip to content

Commit

Permalink
Merge pull request #427 from Homebrew/concurrency
Browse files Browse the repository at this point in the history
cmd/generate-analytics-api: concurrently run commands
  • Loading branch information
MikeMcQuaid authored Jan 19, 2024
2 parents e19d3b4 + 95452d4 commit 4c734ed
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions cmd/generate-analytics-api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,19 @@ def analytics_json_template(category_name, data_source: nil)
end

def run_formula_analytics(*args)
# Give InfluxDB some breathing room.
sleep 4

puts "brew formula-analytics #{args.join(" ")}"

retries = 0
result = system_command HOMEBREW_BREW_FILE, args: ["formula-analytics", *args], print_stderr: false

while !result.success? && retries < MAX_RETRIES
$stderr.puts(result.stderr)

# Give InfluxDB some more breathing room.
sleep 4**(retries+2)

retries += 1
puts "Retrying #{args.join(" ")} (#{retries}/#{MAX_RETRIES})..."
result = system_command HOMEBREW_BREW_FILE, args: ["formula-analytics", *args], print_stderr: false
end

Expand All @@ -75,6 +75,8 @@ def generate_analytics_api
analytics_data_dir = root_dir/"_data/analytics"
analytics_api_dir = root_dir/"api/analytics"

threads = []

CATEGORIES.each do |category|
formula_analytics_args = []

Expand Down Expand Up @@ -120,11 +122,14 @@ def generate_analytics_api
DAYS.each do |days|
next if days != "30" && category_name == "build-error" && !data_source.nil?

args = %W[--days-ago=#{days}]
output = run_formula_analytics(*formula_analytics_args, *args)
(analytics_data_path/"#{days}d.json").write output
(analytics_api_path/"#{days}d.json").write analytics_json_template(category_name, data_source: data_source)
threads << Thread.new do
args = %W[--days-ago=#{days}]
(analytics_data_path/"#{days}d.json").write run_formula_analytics(*formula_analytics_args, *args)
(analytics_api_path/"#{days}d.json").write analytics_json_template(category_name, data_source: data_source)
end
end
end

threads.each(&:join)
end
end

0 comments on commit 4c734ed

Please sign in to comment.