rhod 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.pryrc +2 -1
- data/Changes.md +7 -0
- data/README.md +4 -1
- data/lib/rhod.rb +1 -0
- data/lib/rhod/command.rb +16 -16
- data/lib/rhod/middleware.rb +10 -0
- data/lib/rhod/profile.rb +2 -4
- data/lib/rhod/version.rb +1 -1
- data/test/test_command.rb +12 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4fdc88634e5041f5eb95de18515709647bd9edd2
|
4
|
+
data.tar.gz: fa5cdadac5ca8fcaaef6066862e5b09552b39aee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bb25f0ef2719d5141211eab7f9981938efd5be0dc1fb1a64362280ff844624da0899458e714682e38e6a5021bc7ca7ecc70a48eca151d3b71b260fd7a5733947
|
7
|
+
data.tar.gz: a9d86ea5c9e59a1ea39df024f69bac790adb79c4e87990af471cedff1cc341b7174d9a5bd092661746139f516b2ad0c3caa5725bdd82d15f315cd3d1a8cdd2bb
|
data/.pryrc
CHANGED
@@ -1 +1,2 @@
|
|
1
|
-
require '
|
1
|
+
require 'benchmark'
|
2
|
+
require './lib/rhod'
|
data/Changes.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
# v0.1.2
|
2
|
+
Added logging as a feature - dleung - PR #8
|
3
|
+
|
4
|
+
# v0.1.0 & v0.1.1
|
5
|
+
Changed backoffs to be threadsafe, requiring an API change.
|
6
|
+
Added support for profiles so commonly used Rhod settings could be located in one place.
|
7
|
+
|
1
8
|
# v0.0.3
|
2
9
|
Add support for connection pooling to be attached to a Rhod command.
|
3
10
|
|
data/README.md
CHANGED
@@ -63,6 +63,7 @@ Or install it yourself as:
|
|
63
63
|
|
64
64
|
## Configuration
|
65
65
|
|
66
|
+
### Creating or Editing a New Profile
|
66
67
|
To configure Rhod's defaults, just overwrite the default profile with any changes you'd like to make. If you're on Rails, a good place for your profiles is `config/initializers/rhod.rb`
|
67
68
|
|
68
69
|
```ruby
|
@@ -93,7 +94,9 @@ Rhod.create_profile(:redis,
|
|
93
94
|
retries: 10,
|
94
95
|
backoffs: :^,
|
95
96
|
pool: ConnectionPool.new(size: 3, timeout: 10) { Redis.new },
|
96
|
-
exceptions: [Redis::BaseError]
|
97
|
+
exceptions: [Redis::BaseError],
|
98
|
+
logger: Logger.new("log.txt")
|
99
|
+
)
|
97
100
|
|
98
101
|
Rhod.with_redis("1") {|r, a| r.set('test',a)}
|
99
102
|
# => "OK"
|
data/lib/rhod.rb
CHANGED
data/lib/rhod/command.rb
CHANGED
@@ -3,25 +3,24 @@ class Rhod::Command
|
|
3
3
|
EXCEPTIONS = [Exception, StandardError]
|
4
4
|
|
5
5
|
def initialize(*args, &block)
|
6
|
-
opts
|
7
|
-
@args
|
8
|
-
@args ||= []
|
6
|
+
opts = args[-1].kind_of?(Hash) ? args.pop : {}
|
7
|
+
@args = args || []
|
9
8
|
|
10
|
-
@request
|
9
|
+
@request = block
|
11
10
|
|
12
|
-
@retries
|
13
|
-
@
|
14
|
-
@attempts = 0
|
11
|
+
@retries = opts[:retries] || 0
|
12
|
+
@attempts = 0
|
15
13
|
|
16
|
-
@
|
17
|
-
@backoffs ||= Rhod::Backoffs::Logarithmic.new(1.3)
|
14
|
+
@logger = opts[:logger]
|
18
15
|
|
19
|
-
@
|
16
|
+
@backoffs = Rhod::Backoffs.backoff_sugar_to_enumerator(opts[:backoffs])
|
17
|
+
@backoffs ||= Rhod::Backoffs::Logarithmic.new(1.3)
|
20
18
|
|
21
|
-
@
|
19
|
+
@fallback = opts[:fallback]
|
22
20
|
|
23
|
-
@
|
24
|
-
|
21
|
+
@pool = opts[:pool]
|
22
|
+
|
23
|
+
@exceptions = opts[:exceptions] || EXCEPTIONS
|
25
24
|
end
|
26
25
|
|
27
26
|
### Class methods
|
@@ -44,10 +43,12 @@ class Rhod::Command
|
|
44
43
|
else
|
45
44
|
@request.call(*@args)
|
46
45
|
end
|
47
|
-
rescue *@exceptions
|
46
|
+
rescue *@exceptions => e
|
48
47
|
@attempts += 1
|
48
|
+
@next_attempt = @backoffs.next
|
49
49
|
if @attempts <= @retries
|
50
|
-
|
50
|
+
@logger.warn("Rhod - Caught an exception: #{e.message}. Attempt #{@attempts} in #{sprintf("%.2f", @next_attempt)} secs") if @logger && @logger.respond_to?(:warn)
|
51
|
+
sleep(@next_attempt)
|
51
52
|
retry
|
52
53
|
else
|
53
54
|
return @fallback.call(*@args) if @fallback
|
@@ -55,5 +56,4 @@ class Rhod::Command
|
|
55
56
|
end
|
56
57
|
end
|
57
58
|
end
|
58
|
-
|
59
59
|
end
|
data/lib/rhod/profile.rb
CHANGED
@@ -2,7 +2,7 @@ class Rhod::Profile < Hash
|
|
2
2
|
@@profiles = {}
|
3
3
|
|
4
4
|
def initialize(name, options={})
|
5
|
-
# When creating new profiles, copy from the global default,
|
5
|
+
# When creating new profiles, copy from the global default, in case it was customized.
|
6
6
|
if @@profiles[:default]
|
7
7
|
default = @@profiles[:default].dup
|
8
8
|
else
|
@@ -29,9 +29,7 @@ class Rhod::Profile < Hash
|
|
29
29
|
end
|
30
30
|
|
31
31
|
Rhod::Profile.new(:default,
|
32
|
-
retries:
|
32
|
+
retries: 5,
|
33
33
|
backoffs: Rhod::Backoffs::Logarithmic.new(1.3),
|
34
|
-
fallback: nil,
|
35
|
-
pool: nil,
|
36
34
|
exceptions: [Exception, StandardError],
|
37
35
|
)
|
data/lib/rhod/version.rb
CHANGED
data/test/test_command.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'minitest/autorun'
|
2
|
+
require 'stringio'
|
2
3
|
require File.expand_path(File.dirname(__FILE__) + '/helper')
|
3
4
|
|
4
5
|
describe Rhod::Command do
|
@@ -46,6 +47,17 @@ describe Rhod::Command do
|
|
46
47
|
backoff.verify
|
47
48
|
end
|
48
49
|
|
50
|
+
describe "with logging" do
|
51
|
+
it "logs failures" do
|
52
|
+
test_log = Logger.new(output = StringIO.new)
|
53
|
+
begin
|
54
|
+
Rhod::Command.new(logger: test_log, retries: 1) {raise StandardError}.execute
|
55
|
+
rescue
|
56
|
+
end
|
57
|
+
output.string.must_match(/^W.*Rhod - Caught an exception.*Attempt \d in \d\.\d\d secs$/)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
49
61
|
end
|
50
62
|
|
51
63
|
describe "it uses fallbacks" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rhod
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Bergeron
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-05-
|
11
|
+
date: 2013-05-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -116,6 +116,7 @@ files:
|
|
116
116
|
- lib/rhod/backoffs/logarithmic.rb
|
117
117
|
- lib/rhod/backoffs/random.rb
|
118
118
|
- lib/rhod/command.rb
|
119
|
+
- lib/rhod/middleware.rb
|
119
120
|
- lib/rhod/profile.rb
|
120
121
|
- lib/rhod/version.rb
|
121
122
|
- rhod.gemspec
|