perfect_retry 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5a5d8b36518c3ae65ced85419d129157159d49ff
4
- data.tar.gz: 5d71eb684a0e7a8b15cc3e6435919fdce3e03872
3
+ metadata.gz: c7affaa6359adb9e0f0b436965b8e9c9aa06253d
4
+ data.tar.gz: b64d6075c270e3972eac6b6d485d128dba707c46
5
5
  SHA512:
6
- metadata.gz: afa1392736a1f0e153dd3574ba97b112463deae81e85cf0b850c05df583918064752976b4871cbe9aa618331eb381faf4f2444a81e112f728b203d18c24bf6f5
7
- data.tar.gz: 8f758b82c59ad5a98bc4e40afe7ab03672b8ed1a07fa51f0a44d2b0a3ca5dbc8ec84556adf2214ee13358ff718071a877b82faee6cc25e4ec8ae88b0d00eae62
6
+ metadata.gz: 657ac316050882657e68d6011a004b925b393a575a3e772bcd1a80eb670992cee09004b6b680a9afd95df02303500c3f33d19b68c9af86092a7e2c0dd210b8eb
7
+ data.tar.gz: 8224d23aec68779de177ec4c863b62c93b470a4593602dca9b7090b6e57879a9698638f2673eb08d8614e855928aac82cd301894dbc9ed939c33e2cdee51134a
data/NEWS.md CHANGED
@@ -1,3 +1,8 @@
1
+ # 0.3.0 2015-11-09
2
+
3
+ - [enhancement] Logging backtrace as debug level. [#2](https://github.com/uu59/perfect_retry/pull/2)
4
+ - [enhancement] Add `log_level` option(default: warn) [#2](https://github.com/uu59/perfect_retry/pull/2)
5
+
1
6
  # 0.2.0 2015-11-09
2
7
 
3
8
  - [enhancement] Add `dont_rescues` option.
data/README.md CHANGED
@@ -42,6 +42,10 @@ PerfectRetry.register(:timeout_handling) do |config|
42
42
  # default: Logger.new(STDERR)
43
43
  config.logger = Logger.new("/var/log/agent.log")
44
44
 
45
+ # Logger's log level. Don't change that if `nil` is given. That is useful for pre-configured logger set.
46
+ # default: :info
47
+ config.log_level = :debug
48
+
45
49
  # Ensure block. Call this block after with_retry block finished with and without any errors.
46
50
  # default: proc {}
47
51
  config.ensure = proc { puts "finished" }
data/lib/perfect_retry.rb CHANGED
@@ -11,6 +11,7 @@ class PerfectRetry
11
11
  rescues: [StandardError],
12
12
  dont_rescues: [],
13
13
  logger: Logger.new(STDERR),
14
+ log_level: :info,
14
15
  sleep: lambda{|n| n ** 2},
15
16
  ensure: lambda{},
16
17
  }.freeze
@@ -42,6 +43,7 @@ class PerfectRetry
42
43
  def initialize(config_key = nil, &block)
43
44
  @config = REGISTERED_CONFIG[config_key] || default_config
44
45
  block.call(@config) if block_given?
46
+ @config.set_log_level
45
47
  end
46
48
 
47
49
  def default_config
@@ -55,6 +57,10 @@ class PerfectRetry
55
57
  rescue *config.dont_rescues => e
56
58
  raise e
57
59
  rescue *config.rescues => e
60
+ e.backtrace.each do |line|
61
+ config.logger.debug line
62
+ end
63
+
58
64
  if should_retry?(count)
59
65
  count += 1
60
66
  config.logger.warn "[#{count}/#{config.limit || "Infinitiy"}] Retrying after #{config.sleep_sec(count)} seconds. Ocurred: #{e}(#{e.class})"
@@ -1,7 +1,7 @@
1
1
  require "logger"
2
2
 
3
3
  class PerfectRetry
4
- class Config < Struct.new(:limit, :rescues, :dont_rescues, :logger, :sleep, :ensure)
4
+ class Config < Struct.new(:limit, :rescues, :dont_rescues, :logger, :sleep, :ensure, :log_level)
5
5
  def self.create_from_hash(hash)
6
6
  config = new
7
7
  hash.each do |k, v|
@@ -10,6 +10,24 @@ class PerfectRetry
10
10
  config
11
11
  end
12
12
 
13
+ def set_log_level
14
+ case log_level
15
+ when Fixnum
16
+ logger.level = log_level
17
+ return
18
+ when String, Symbol
19
+ if int = Logger::SEV_LABEL.index(log_level.to_s.upcase)
20
+ logger.level = int
21
+ return
22
+ end
23
+ when nil
24
+ # Don't touch when nil
25
+ return
26
+ end
27
+
28
+ raise "Unknown log level '#{log_level}'(#{log_level.class})"
29
+ end
30
+
13
31
  def sleep_sec(count)
14
32
  if sleep.is_a?(Proc)
15
33
  sleep.call(count)
@@ -1,3 +1,3 @@
1
1
  class PerfectRetry
2
- VERSION = "0.2.0".freeze
2
+ VERSION = "0.3.0".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: perfect_retry
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - uu59
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-11-09 00:00:00.000000000 Z
11
+ date: 2015-11-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler