Class: Homebrew::DevCmd::GenerateAnalyticsApi Private
- Inherits:
-
AbstractCommand
- Object
- AbstractCommand
- Homebrew::DevCmd::GenerateAnalyticsApi
- Defined in:
- dev-cmd/generate-analytics-api.rb,
sorbet/rbi/dsl/homebrew/dev_cmd/generate_analytics_api.rbi
This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.
Defined Under Namespace
Classes: Args
Constant Summary collapse
- CATEGORIES =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
%w[ build-error install install-on-request core-build-error core-install core-install-on-request cask-install core-cask-install os-version homebrew-devcmdrun-developer homebrew-os-arch-ci homebrew-prefixes homebrew-versions brew-command-run brew-command-run-options brew-test-bot-test ].freeze
- DAYS =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
TODO:add brew-command-run-options brew-test-bot-test to above when working.
%w[30 90 365].freeze
- MAX_RETRIES =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
3
Instance Method Summary collapse
- #analytics_json_template(category_name, data_source: nil) ⇒ String private
- #args ⇒ Homebrew::DevCmd::GenerateAnalyticsApi::Args private
- #run ⇒ void private
- #run_formula_analytics(*args) ⇒ String private
Methods inherited from AbstractCommand
command, command_name, dev_cmd?, #initialize, parser, ruby_cmd?
Constructor Details
This class inherits a constructor from Homebrew::AbstractCommand
Instance Method Details
#analytics_json_template(category_name, data_source: nil) ⇒ String
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'dev-cmd/generate-analytics-api.rb', line 33 def analytics_json_template(category_name, data_source: nil) data_source = "#{data_source}: true" if data_source <<~EOS --- layout: analytics_json category: #{category_name} #{data_source} --- {{ content }} EOS end |
#args ⇒ Homebrew::DevCmd::GenerateAnalyticsApi::Args
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
10 |
# File 'sorbet/rbi/dsl/homebrew/dev_cmd/generate_analytics_api.rbi', line 10 def args; end |
#run ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'dev-cmd/generate-analytics-api.rb', line 68 def run safe_system HOMEBREW_BREW_FILE, "formula-analytics", "--setup" directories = ["_data/analytics", "api/analytics"] FileUtils.rm_rf directories FileUtils.mkdir_p directories root_dir = Pathname.pwd analytics_data_dir = root_dir/"_data/analytics" analytics_api_dir = root_dir/"api/analytics" threads = [] CATEGORIES.each do |category| formula_analytics_args = [] case category when "core-build-error" formula_analytics_args << "--all-core-formulae-json" formula_analytics_args << "--build-error" category_name = "build-error" data_source = "homebrew-core" when "core-install" formula_analytics_args << "--all-core-formulae-json" formula_analytics_args << "--install" category_name = "install" data_source = "homebrew-core" when "core-install-on-request" formula_analytics_args << "--all-core-formulae-json" formula_analytics_args << "--install-on-request" category_name = "install-on-request" data_source = "homebrew-core" when "core-cask-install" formula_analytics_args << "--all-core-formulae-json" formula_analytics_args << "--cask-install" category_name = "cask-install" data_source = "homebrew-cask" else formula_analytics_args << "--#{category}" category_name = category end path_suffix = File.join(category_name, data_source || "") analytics_data_path = analytics_data_dir/path_suffix analytics_api_path = analytics_api_dir/path_suffix FileUtils.mkdir_p analytics_data_path FileUtils.mkdir_p analytics_api_path # The `--json` and `--all-core-formulae-json` flags are mutually # exclusive, but we need to explicitly set `--json` sometimes, # so only set it if we've not already set # `--all-core-formulae-json`. formula_analytics_args << "--json" unless formula_analytics_args.include? "--all-core-formulae-json" DAYS.each do |days| next if days != "30" && category_name == "build-error" && !data_source.nil? 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:) end end end threads.each(&:join) end |
#run_formula_analytics(*args) ⇒ String
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'dev-cmd/generate-analytics-api.rb', line 47 def run_formula_analytics(*args) puts "brew formula-analytics #{args.join(" ")}" retries = 0 result = Utils.popen_read(HOMEBREW_BREW_FILE, "formula-analytics", *args, err: :err) while !$CHILD_STATUS.success? && retries < MAX_RETRIES # Give InfluxDB some more breathing room. sleep 4**(retries+2) retries += 1 puts "Retrying #{args.join(" ")} (#{retries}/#{MAX_RETRIES})..." result = Utils.popen_read(HOMEBREW_BREW_FILE, "formula-analytics", *args, err: :err) end odie "`brew formula-analytics #{args.join(" ")}` failed: #{result}" unless $CHILD_STATUS.success? result end |