Permalink
Browse files

Merge branch 'remove-run-reporter' -- a worthwhile experiment, but...

The reports turned out not to be very useful, mainly because the most
substantial and interesting deps people run are either private, or not knowably
public at runtime (e.g. in a public source, but cloned from a read+write ssh
remote). This meant that the data collected was only a thin slice of the total
usage.

Secondly, having a community database makes it easy to find and run deps
without checking what they do. This wasn't my intention, and I don't know of
anyone actually doing this, but I don't think it's wise to help this behaviour.
I still want running others' deps to be easy (i.e. `babushka source:dep`), but
listing deps in the community DB might be mistaken for an endorsement.
  • Loading branch information...
benhoskings committed Mar 31, 2013
2 parents bbf5058 + aba9e95 commit 9741eb36a5b35126595baf4274eba0d026cdfcfb
View
@@ -57,21 +57,11 @@ def sources
@sources ||= SourcePool.new(cmdline.opts.slice(:update))
end
- def threads
- @threads ||= []
- end
-
- def in_thread &block
- threads.push Thread.new(&block)
- end
-
# The top-level entry point for babushka runs invoked at the command line.
# When the `babushka` command is run, bin/babushka.rb first triggers a load
# via lib/babushka.rb, and then calls this method.
def run
cmdline.run
- ensure
- threads.each(&:join)
end
def exit_on_interrupt!
View
@@ -90,25 +90,6 @@ class Cmdline
exec "irb -r'#{Path.lib / 'babushka'}' --simple-prompt"
}
- handle('search', "Search for deps in the community database").run {|cmd|
- if cmd.argv.length != 1
- fail_with "'search' requires a single argument."
- else
- require 'net/http'
- require 'yaml'
-
- search_term = cmd.argv.first
- results = Helpers.search_results_for(search_term)
-
- if results.empty?
- log "Never seen a dep with '#{search_term}' in its name."
- else
- Helpers.print_search_results search_term, results
- true
- end
- end
- }
-
handle('edit', "Load the file containing the specified dep in $EDITOR").run {|cmd|
if cmd.argv.length != 1
fail_with "'edit' requires a single argument."
@@ -47,46 +47,10 @@ def self.print_notes
log " e.g. '#{Base.program_name} l' is short for '#{Base.program_name} list'."
end
- def self.search_results_for q
- YAML.load(search_webservice_for(q).body).sort_by {|i|
- -i[:runs_this_week]
- }.map {|i|
- [
- i[:name],
- i[:source_uri],
- ((i[:runs_this_week] && i[:runs_this_week] > 0) ? "#{i[:runs_this_week]} this week" : "#{i[:total_runs]} ever"),
- ((i[:runs_this_week] && i[:runs_this_week] > 0) ? "#{(i[:success_rate_this_week] * 100).round}%" : ((i[:total_runs] && i[:total_runs] > 0) ? "#{(i[:total_success_rate] * 100).round}%" : '')),
- (i[:source_uri][github_autosource_regex] ? "#{Base.program_name} #{$1}:#{"'" if i[:name][/\s/]}#{i[:name]}#{"'" if i[:name][/\s/]}" : '')
- ]
- }
- end
-
- def self.print_search_results search_term, results
- log "The webservice knows about #{results.length} dep#{'s' unless results.length == 1} that match#{'es' if results.length == 1} '#{search_term}':"
- log ""
- Logging.log_table(
- ['Name', 'Source', 'Runs', '', 'Command'],
- results
- )
- if (custom_sources = results.select {|r| r[1][github_autosource_regex].nil? }.length) > 0
- log ""
- log "#{custom_sources == 1 ? 'This source has a custom URI' : 'These sources have custom URIs'}, so babushka can't discover #{custom_sources == 1 ? 'it' : 'them'} automatically."
- log " You can run #{custom_sources == 1 ? 'its' : 'their'} deps in the same way, though, once you add #{custom_sources == 1 ? 'it' : 'them'} manually:"
- log " $ #{Base.program_name} sources -a <alias> <uri>"
- log " $ #{Base.program_name} <alias>:<dep>"
- end
- end
-
def self.github_autosource_regex
/^\w+\:\/\/github\.com\/(.*)\/babushka-deps(\.git)?/
end
- def self.search_webservice_for q
- Net::HTTP.start('babushka.me') {|http|
- http.get URI.escape("/deps/search.yaml/#{q}")
- }
- end
-
def self.generate_list_for to_list, filter_str
context = to_list == :deps ? Base.program_name : ':template =>'
match_str = filter_str.try(:downcase)
@@ -1,69 +0,0 @@
-module Babushka
- class RunReporter
- class << self
- include LogHelpers
-
- def queue dep, result, reportable
- if dep.dep_source.type != :public
- debug "Not reporting #{dep.contextual_name}, since it's not in a public source."
- else
- queue_report dep, (reportable ? 'error' : (result ? 'ok' : 'fail'))
- end
- end
-
- def post_reports
- require 'net/http'
-
- while Base.task.running? && (report = most_recent_report)
- post_report report
- end
- end
-
-
- private
-
- def post_report report
- submit_report_to_webservice(report.p.read).tap {|result|
- if result.is_a?(Net::HTTPSuccess) || result.is_a?(Net::HTTPNotAcceptable)
- # Remove the run on success, and on validation error: retrying
- # won't help that anyway.
- report.p.rm
- else
- # Wait for a moment before trying again, so persistent problems don't
- # slam babushka.me (if it's rejecting the data) or peg our CPU (if
- # the network is down).
- sleep 1
- end
- }
- end
-
- require 'net/http'
- def submit_report_to_webservice data
- Net::HTTP.start('babushka.me') {|http|
- http.open_timeout = http.read_timeout = 5
- http.post '/runs.json', data
- }
- rescue Errno::EADDRNOTAVAIL, Errno::ECONNREFUSED, SocketError
- log_error "Couldn't connect to the babushka webservice." unless Base.task.running?
- rescue Timeout::Error, Errno::ETIMEDOUT
- debug "Timeout while submitting run report."
- end
-
- def most_recent_report
- ReportPrefix.p.glob('*').sort.last
- end
-
- def queue_report dep, result
- ReportPrefix.p.mkdir
- (ReportPrefix / Time.now.to_f).open('w') {|f|
- f << run_report_for(dep, result).to_http_params
- }
- end
-
- def run_report_for dep, result
- Base.task.task_info(dep, result)
- end
-
- end
- end
-end
View
@@ -21,8 +21,7 @@ def process dep_names, with_args, cmd
raise "A task is already running." if running?
@cmd = cmd
@running = true
- cleanup_saved_vars # TODO: remove after August '13 or so.
- Base.in_thread { RunReporter.post_reports }
+ cleanup_obsolete_data # TODO: remove after August '13 or so.
dep_names.all? {|dep_name| process_dep(dep_name, with_args) }
rescue SourceLoadError => e
Babushka::Logging.log_exception(e)
@@ -36,7 +35,6 @@ def process_dep dep_name, with_args
dep.with(task_args_for(dep, with_args)).process(!opt(:dry_run))
}.tap {|result|
log_stderr "You can view #{opt(:debug) ? 'the' : 'a more detailed'} log at '#{log_path_for(dep)}'." unless result
- RunReporter.queue(dep, result, reportable)
BugReporter.report(dep) if reportable
}
end
@@ -61,17 +59,6 @@ def cached key, opts = {}, &block
end
end
- def task_info dep, result
- {
- :version => Base.ref,
- :run_at => Time.now,
- :system_info => Babushka.host.description,
- :dep_name => dep.name,
- :source_uri => dep.dep_source.uri,
- :result => result
- }
- end
-
def opt name
cmd.opts[name] unless cmd.nil?
end
@@ -121,8 +108,9 @@ def log_prefix
LogPrefix.p
end
- def cleanup_saved_vars
+ def cleanup_obsolete_data
VarsPrefix.p.rm if VarsPrefix.p.exists?
+ ReportPrefix.p.rm if ReportPrefix.p.exists?
end
end
View
@@ -50,7 +50,6 @@ module Babushka
system_profile
system_detector
system_matcher
- run_reporter
bug_reporter
pkg_helper
pkg_helpers/unknown_pkg_helper
@@ -18,7 +18,6 @@
" meet The main one: run a dep and all its dependencies.",
" sources Manage dep sources",
" console Start an interactive (irb-based) babushka session",
- " search Search for deps in the community database",
" edit Load the file containing the specified dep in $EDITOR",
"\nCommands can be abbrev'ed, as long as they remain unique.",
" e.g. '#{Base.program_name} l' is short for '#{Base.program_name} list'.",

0 comments on commit 9741eb3

Please sign in to comment.