-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GPA Improvements: 1.15 to 2.02 #79
base: master
Are you sure you want to change the base?
Changes from 4 commits
8065194
1ec8d07
9f5ce24
f94fa06
bcf1c95
d2b75a6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- | ||
engines: | ||
duplication: | ||
enabled: true | ||
config: | ||
languages: | ||
- ruby | ||
|
||
fixme: | ||
enabled: true | ||
|
||
rubocop: | ||
enabled: true | ||
|
||
ratings: | ||
paths: | ||
- "**.rb" | ||
|
||
exclude_paths: | ||
- lib/papertrail/okjson.rb | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,7 +29,7 @@ def initialize | |
end | ||
|
||
def run | ||
if configfile = find_configfile | ||
if configfile | ||
configfile_options = load_configfile(configfile) | ||
options.merge!(configfile_options) | ||
end | ||
|
@@ -38,11 +38,11 @@ def run | |
opts.banner = "papertrail - command-line tail and search for Papertrail log management service" | ||
opts.version = Papertrail::VERSION | ||
|
||
opts.on("-h", "--help", "Show usage") do |v| | ||
opts.on("-h", "--help", "Show usage") do | ||
puts opts | ||
exit | ||
end | ||
opts.on("-f", "--follow", "Continue running and printing new events (off)") do |v| | ||
opts.on("-f", "--follow", "Continue running and printing new events (off)") do | ||
options[:follow] = true | ||
end | ||
opts.on("--min-time MIN", "Earliest time to search from") do |v| | ||
|
@@ -66,15 +66,15 @@ def run | |
opts.on("-s", "--system SYSTEM", "System to search") do |v| | ||
options[:system] = v | ||
end | ||
opts.on("-j", "--json", "Output raw JSON data (off)") do |v| | ||
opts.on("-j", "--json", "Output raw JSON data (off)") do | ||
options[:json] = true | ||
end | ||
opts.on("--color [program|system|all|off]", | ||
[:program, :system, :all, :off], | ||
"Attribute(s) to colorize based on (program)") do |v| | ||
opts.on("--color [program|system|all|off]", | ||
[:program, :system, :all, :off], "Attribute(s) to colorize based on (program)") do |v| | ||
|
||
options[:color] = v | ||
end | ||
opts.on("--force-color", "Force use of ANSI color characters even on non-tty outputs (off)") do |v| | ||
opts.on("--force-color", "Force use of ANSI color characters even on non-tty outputs (off)") do | ||
options[:force_color] = true | ||
end | ||
opts.on("-V", "--version", "Display the version and exit") do |v| | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here's another unused block argument. |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,47 +42,27 @@ def get(path, params = {}) | |
if params.size > 0 | ||
path = "#{path}?#{build_nested_query(params)}" | ||
end | ||
attempts = 0 | ||
begin | ||
|
||
attempt 3, 5.0 do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it'd be easier to understand if the arguments to |
||
on_complete(https.get(request_uri(path), @headers)) | ||
rescue SystemCallError, Net::HTTPFatalError => e | ||
sleep 5.0 | ||
attempts += 1 | ||
retry if (attempts < 3) | ||
raise e | ||
end | ||
end | ||
|
||
def put(path, params) | ||
attempts = 0 | ||
begin | ||
attempt do | ||
on_complete(https.put(request_uri(path), build_nested_query(params), @headers)) | ||
rescue SystemCallError, Net::HTTPFatalError => e | ||
attempts += 1 | ||
retry if (attempts < 3) | ||
raise e | ||
end | ||
end | ||
|
||
def post(path, params) | ||
attempts = 0 | ||
begin | ||
attempt do | ||
on_complete(https.post(request_uri(path), build_nested_query(params), @headers)) | ||
rescue SystemCallError, Net::HTTPFatalError => e | ||
attempts += 1 | ||
retry if (attempts < 3) | ||
raise e | ||
end | ||
end | ||
|
||
def delete(path) | ||
attempts = 0 | ||
begin | ||
attempt do | ||
on_complete(https.delete(request_uri(path), @headers)) | ||
rescue SystemCallError, Net::HTTPFatalError => e | ||
attempts += 1 | ||
retry if (attempts < 3) | ||
raise e | ||
end | ||
end | ||
|
||
|
@@ -156,6 +136,21 @@ def escape(s) | |
'%' + $&.unpack('H2' * $&.bytesize).join('%').upcase | ||
}.tr(' ', '+') | ||
end | ||
|
||
def attempt(tries=3, wait=nil) | ||
return unless block_given? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this is an internal method to this class, I think it's fine to let this method blow up when calling |
||
|
||
attempts = 0 | ||
begin | ||
yield | ||
rescue => e | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We'll want to continue rescuing |
||
sleep wait if wait | ||
attempts += 1 | ||
retry if (attempts < tries) | ||
raise e | ||
end | ||
end | ||
|
||
end | ||
|
||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I usually avoid adding codeclimate.yml (less clutter), but it is needed if we want to exclude the vendored
okjson
(which pulls the gpa down quite a bit...)