Sha256: 371cb56807b92b3a6e199be4d516e6d2a5fc2e2d5941d192ae21a33fabec068c
Contents?: true
Size: 1.94 KB
Versions: 9
Compression:
Stored size: 1.94 KB
Contents
module ActiveRecord module SqlAnalyzer class CLI attr_reader :options, :processor def initialize @options = { concurrency: 6 } end def processor @processor ||= ActiveRecord::SqlAnalyzer::CLIProcessor.new(options[:concurrency]) end def run definition_logs = Dir["#{options[:log_dir]}/*_definitions.log*"].map do |path| [File.basename(path).gsub(/_definitions\.log.*/, ""), path] end if definition_logs.empty? raise ArgumentError, "Cannot find any log files in '#{options[:log_dir]}'" end # Process the definition logs processor.run_definition(definition_logs) # Process the usage logs usage_logs = Dir["#{options[:log_dir]}/{#{definition_logs.map(&:first).uniq.join(",")}}.log*"].map do |path| [File.basename(path).split(".", 2).first, path] end processor.run_usage(usage_logs) processor.dump(options[:dest_dir]) end def parse_options(args) opts = OptionParser.new opts.on("--log-dir [DIR]", String, "Directory that logs are in") do |val| unless Dir.exist?(val) raise ArgumentError, "log directory '#{val}' does not exist" end options[:log_dir] = val end opts.on("--dest-dir [DIR]", String, "Directory to dump logs to") do |val| unless Dir.exist?(val) raise ArgumentError, "dest directory '#{val}' does not exist" end options[:dest_dir] = val end opts.on("-c", "--concurrency", Integer, "How many threads to use for processing log files") do |val| if val <= 0 raise ArgumentError, "Concurrency must be >0" end options[:concurrency] = val end opts.on_tail("-h", "--help") do puts opts exit end opts.parse(args) end end end end
Version data entries
9 entries across 9 versions & 1 rubygems