greenjaguar 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +18 -1
- data/greenjaguar.gemspec +0 -1
- data/lib/greenjaguar/policy_builder.rb +3 -3
- data/lib/greenjaguar/version.rb +1 -1
- data/spec/greenjaguar_spec.rb +9 -9
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5dd4f387ad0f79d53b1622d411199d55cb640d2c
|
4
|
+
data.tar.gz: 46b57205cb9a7bbac6aa9df87f24d1d92f3243ba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e425dc9d9967cb79eef0d516e2fccb57c23613d259e0067b0d97c62e645029da63e23fc58623d7ce4f182dfeaf6e9ed17bc7927bc6584e3ca5331972dff12812
|
7
|
+
data.tar.gz: ce72b91c424aea7cef0c52ba55230a05e7ed27e058022d4057f79da81e6db5ba2668e6c23fe035e9574798f7ab778d09b28515454f20096ea0a503f29aa9db7e
|
data/README.md
CHANGED
@@ -45,7 +45,7 @@ class YourClass
|
|
45
45
|
def your_method
|
46
46
|
# Build retry policy
|
47
47
|
@policy = build_policy do
|
48
|
-
|
48
|
+
times 10
|
49
49
|
with_strategy :exponential_backoff
|
50
50
|
measure_time_in :ms
|
51
51
|
only_on_exceptions [Net::HTTPError]
|
@@ -63,6 +63,23 @@ In the above example your code block is passed to Greenjaguar which executes it
|
|
63
63
|
If all calls fail, the last exception is raised. Retry happens only if the error raised is of the
|
64
64
|
specified type.
|
65
65
|
|
66
|
+
## Available Options explained
|
67
|
+
- times: Number of retry attempts
|
68
|
+
- with_strategy: Retry Strategy to use. Greenjaguar currently supports following
|
69
|
+
- exponential_backoff: wait times after each failed retry will increase exponentially. This is the standard
|
70
|
+
used in most of the industry's retry policies.
|
71
|
+
- fibonacci: wait times increase in fibonacci series.
|
72
|
+
- fixed_interval: wait times between retries are fixed.
|
73
|
+
- random: wait times are randomly selected between 0 to 5 secs.
|
74
|
+
Skip this option if you want immediate retries.
|
75
|
+
- measure_time_in: wait times can be in either sec or ms.
|
76
|
+
- only_on_exceptions: Provide the Exception Types for which Greenjaguar should retry. Default is all.
|
77
|
+
- fail_silently: Will fail silently without raising any exceptions after all retries fail.
|
78
|
+
- never_give_up: Retry will continue indefinitely or until there is success.
|
79
|
+
- timeout_after: Set a timeout period after which Greenjaguar should quit and just raise the exception.
|
80
|
+
|
81
|
+
Refer spec/greenjaguar_spec.rb to se examples of using the options.
|
82
|
+
|
66
83
|
## Issues
|
67
84
|
|
68
85
|
1. Need more tests.
|
data/greenjaguar.gemspec
CHANGED
@@ -10,7 +10,6 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["anides84 AT hotmail DOT com"]
|
11
11
|
spec.summary = %q{Applies retry behavior to arbitrary code blocks with different policies like fibonacci,
|
12
12
|
exponential backoff, FixedInterval, etc. This basically is the 'retry' construct on steroids.}
|
13
|
-
spec.description = ""
|
14
13
|
spec.homepage = "https://github.com/aniruddha84/greenjaguar"
|
15
14
|
spec.license = "MIT"
|
16
15
|
|
@@ -9,17 +9,17 @@ module Greenjaguar
|
|
9
9
|
instance_eval(&block)
|
10
10
|
end
|
11
11
|
|
12
|
-
def
|
12
|
+
def times(retry_count)
|
13
13
|
@count = retry_count
|
14
14
|
self
|
15
15
|
end
|
16
16
|
|
17
|
-
def
|
17
|
+
def timeout_after(retry_timeout)
|
18
18
|
@timeout = retry_timeout
|
19
19
|
self
|
20
20
|
end
|
21
21
|
|
22
|
-
def
|
22
|
+
def logger(logger)
|
23
23
|
@logger = logger
|
24
24
|
self
|
25
25
|
end
|
data/lib/greenjaguar/version.rb
CHANGED
data/spec/greenjaguar_spec.rb
CHANGED
@@ -16,7 +16,7 @@ module Specs
|
|
16
16
|
|
17
17
|
it '#run should call the passed code block 4 times' do
|
18
18
|
policy = class_under_test.build_policy do
|
19
|
-
|
19
|
+
times 3
|
20
20
|
end
|
21
21
|
|
22
22
|
expect do
|
@@ -31,7 +31,7 @@ module Specs
|
|
31
31
|
@stub = stub_request(:get, "http://www.example.com")
|
32
32
|
|
33
33
|
policy = class_under_test.build_policy do
|
34
|
-
|
34
|
+
times 3
|
35
35
|
end
|
36
36
|
|
37
37
|
class_under_test.robust_retry(policy) do
|
@@ -42,7 +42,7 @@ module Specs
|
|
42
42
|
|
43
43
|
it '#run should raise the error once retrying is completed' do
|
44
44
|
policy = class_under_test.build_policy do
|
45
|
-
|
45
|
+
times 3
|
46
46
|
end
|
47
47
|
|
48
48
|
expect do
|
@@ -54,7 +54,7 @@ module Specs
|
|
54
54
|
|
55
55
|
it '#run should call the passed code block 4 times according to fibonacci sequence' do
|
56
56
|
policy = class_under_test.build_policy do
|
57
|
-
|
57
|
+
times 3
|
58
58
|
with_strategy :fibonacci
|
59
59
|
measure_time_in :ms
|
60
60
|
end
|
@@ -69,7 +69,7 @@ module Specs
|
|
69
69
|
|
70
70
|
it '#run should call the passed code block 4 times according to fixed interval strategy' do
|
71
71
|
policy = class_under_test.build_policy do
|
72
|
-
|
72
|
+
times 3
|
73
73
|
with_strategy :fixed_interval, 2
|
74
74
|
measure_time_in :ms
|
75
75
|
end
|
@@ -84,7 +84,7 @@ module Specs
|
|
84
84
|
|
85
85
|
it '#run should call the passed code block 4 times according to exponential backoff sequence' do
|
86
86
|
policy = class_under_test.build_policy do
|
87
|
-
|
87
|
+
times 5
|
88
88
|
with_strategy :exponential_backoff
|
89
89
|
measure_time_in :ms
|
90
90
|
end
|
@@ -100,7 +100,7 @@ module Specs
|
|
100
100
|
it '#run does not call the passed code block if exception is not part of allowed exception(s)' do
|
101
101
|
@stub = stub_request(:get, "www.example.com").to_raise(RegexpError)
|
102
102
|
policy = class_under_test.build_policy do
|
103
|
-
|
103
|
+
times 5
|
104
104
|
with_strategy :fibonacci
|
105
105
|
only_on_exceptions [ZeroDivisionError]
|
106
106
|
end
|
@@ -117,7 +117,7 @@ module Specs
|
|
117
117
|
@stub = stub_request(:get, "http://www.example.com").to_raise(ZeroDivisionError)
|
118
118
|
|
119
119
|
policy = class_under_test.build_policy do
|
120
|
-
|
120
|
+
times 10
|
121
121
|
with_strategy :fibonacci
|
122
122
|
measure_time_in :ms
|
123
123
|
only_on_exceptions [ZeroDivisionError, IOError]
|
@@ -133,7 +133,7 @@ module Specs
|
|
133
133
|
|
134
134
|
it '#run should not raise the error if set to fail silently' do
|
135
135
|
policy = class_under_test.build_policy do
|
136
|
-
|
136
|
+
times 3
|
137
137
|
fail_silently
|
138
138
|
end
|
139
139
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: greenjaguar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aniruddha Deshpande
|
@@ -108,7 +108,7 @@ dependencies:
|
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '1.21'
|
111
|
-
description:
|
111
|
+
description:
|
112
112
|
email:
|
113
113
|
- anides84 AT hotmail DOT com
|
114
114
|
executables: []
|