attempt_this 0.9.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile.lock +1 -1
- data/README.md +11 -2
- data/attempt_this.gemspec +2 -2
- data/lib/attempt_this/attempt_object.rb +1 -0
- data/lib/attempt_this/attempt_this.rb +8 -0
- data/spec/attempt_spec.rb +55 -1
- metadata +20 -35
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: bb1e8ce9d65d7e2fd649b08462f7fec5d5c275bd
|
4
|
+
data.tar.gz: 42f3dfabe605a339c8f0abaa32db1e93ee130532
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 67d984ccaa89933fefd5fc20358c11750baaecc56f47ba10625deac47312d8d9a46a9c41b36803461d7b6b0a6150dceec8addf7ef57dfbb7f352fa3aabcea597
|
7
|
+
data.tar.gz: cf0c8ab119c22978d0328d930b05e34e54f89ea57b4d15b4af4c7597f068b04245ff68efdea4fe07816756eaa2c35280f648ec1f13be7c122507165aa09b18ef
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -68,8 +68,7 @@ attempt(3.times)
|
|
68
68
|
end
|
69
69
|
```
|
70
70
|
|
71
|
-
|
72
|
-
|
71
|
+
You can store various configurations as scenarios and use them by name. This is useful when you need different approaches for specific cases (handling HTTP failures, for example). But remember that you should register your scenarios before using them:
|
73
72
|
```ruby
|
74
73
|
# Run this code when the application starts
|
75
74
|
AttemptThis.attempt(5.times).with_filter(*RECOVERABLE_HTTP_ERRORS).scenario(:http)
|
@@ -84,4 +83,14 @@ end
|
|
84
83
|
# Return values
|
85
84
|
Calling 'attempt' will return result of the code block if there was no exception; otherwise it will return result of the default handler.
|
86
85
|
|
86
|
+
# Debugging
|
87
|
+
You may want to disable all retries and let everything fail on the very first attempt as if there was no rerty policy at all; this is useful for debugging (consider investigating an issue inside a code block that should be retried for 20 minutes before the exception surfaces). In this case you can simply disable all retry policies in your project by setting global "enabled" property:
|
88
|
+
```ruby
|
89
|
+
# Disable all retry policies for now...
|
90
|
+
AttemptThis.enabled = false
|
91
|
+
|
92
|
+
puts AttemptThis.enabled?
|
93
|
+
```
|
94
|
+
|
95
|
+
|
87
96
|
Enjoy! And feel free to contribute; just make sure you haven't broken any tests by running 'rake' from project's root.
|
data/attempt_this.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'attempt_this'
|
3
|
-
s.version = '0.
|
4
|
-
s.date = '2014-
|
3
|
+
s.version = '1.0.0'
|
4
|
+
s.date = '2014-04-27'
|
5
5
|
s.summary = 'Retry policy mix-in'
|
6
6
|
s.description = <<EOM
|
7
7
|
Retry policy mix-in with configurable number of attempts, delays, exception filters, and fall back strategies.
|
@@ -11,6 +11,14 @@ module AttemptThis
|
|
11
11
|
impl.attempt(block)
|
12
12
|
end
|
13
13
|
|
14
|
+
def enabled?
|
15
|
+
@enabled.nil? || @enabled
|
16
|
+
end
|
17
|
+
|
18
|
+
def enabled=(value)
|
19
|
+
@enabled = value
|
20
|
+
end
|
21
|
+
|
14
22
|
# Resets all static data (scenarios). This is intended to use by tests only (to reset scenarios)
|
15
23
|
def self.reset
|
16
24
|
AttemptObject.reset
|
data/spec/attempt_spec.rb
CHANGED
@@ -293,4 +293,58 @@ describe AttemptThis do
|
|
293
293
|
count.should eql(3)
|
294
294
|
end
|
295
295
|
end
|
296
|
-
|
296
|
+
|
297
|
+
context 'enabled' do
|
298
|
+
class TestAttempt
|
299
|
+
include AttemptThis
|
300
|
+
end
|
301
|
+
|
302
|
+
subject{TestAttempt.new}
|
303
|
+
|
304
|
+
it 'should be true initially' do
|
305
|
+
subject.enabled?.should be_true
|
306
|
+
end
|
307
|
+
|
308
|
+
it 'should accept true' do
|
309
|
+
subject.enabled = true
|
310
|
+
subject.enabled?.should be_true
|
311
|
+
end
|
312
|
+
|
313
|
+
it 'should accept false' do
|
314
|
+
subject.enabled = false
|
315
|
+
subject.enabled?.should be_false
|
316
|
+
end
|
317
|
+
|
318
|
+
it 'should change from true to false' do
|
319
|
+
subject.enabled = true
|
320
|
+
subject.enabled = false
|
321
|
+
subject.enabled?.should be_false
|
322
|
+
end
|
323
|
+
|
324
|
+
it 'should change from false to true' do
|
325
|
+
subject.enabled = false
|
326
|
+
subject.enabled = true
|
327
|
+
subject.enabled?.should be_true
|
328
|
+
end
|
329
|
+
|
330
|
+
context 'when disabled' do
|
331
|
+
before(:each) do
|
332
|
+
AttemptThis.stub(:enabled?).and_return(false)
|
333
|
+
end
|
334
|
+
|
335
|
+
it 'should yield in the simplest case' do
|
336
|
+
expect{|b| attempt(3.times, &b)}.to yield_control
|
337
|
+
end
|
338
|
+
|
339
|
+
it 'should yield with chained calls' do
|
340
|
+
expect{|b| attempt(3.times).with_delay(100, &b)}.to yield_control
|
341
|
+
end
|
342
|
+
|
343
|
+
it 'should not retry' do
|
344
|
+
count = 0
|
345
|
+
expect{attempt(3.times) {count += 1; raise 'Test'}}.to raise_error('Test')
|
346
|
+
count.should eql(1)
|
347
|
+
end
|
348
|
+
end
|
349
|
+
end
|
350
|
+
end
|
metadata
CHANGED
@@ -1,103 +1,89 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: attempt_this
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 1.0.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Aliaksei Baturytski
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2014-
|
11
|
+
date: 2014-04-27 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: bundler
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - '>='
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rake
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - '>='
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - '>='
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: rspec
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - '>='
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: '0'
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - '>='
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: '0'
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: simplecov
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
|
-
- -
|
59
|
+
- - '>='
|
68
60
|
- !ruby/object:Gem::Version
|
69
61
|
version: '0'
|
70
62
|
type: :development
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
|
-
- -
|
66
|
+
- - '>='
|
76
67
|
- !ruby/object:Gem::Version
|
77
68
|
version: '0'
|
78
69
|
- !ruby/object:Gem::Dependency
|
79
70
|
name: uuid
|
80
71
|
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
72
|
requirements:
|
83
|
-
- -
|
73
|
+
- - '>='
|
84
74
|
- !ruby/object:Gem::Version
|
85
75
|
version: '0'
|
86
76
|
type: :development
|
87
77
|
prerelease: false
|
88
78
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
79
|
requirements:
|
91
|
-
- -
|
80
|
+
- - '>='
|
92
81
|
- !ruby/object:Gem::Version
|
93
82
|
version: '0'
|
94
|
-
description:
|
95
|
-
exception filters, and fall back strategies.
|
83
|
+
description: |
|
84
|
+
Retry policy mix-in with configurable number of attempts, delays, exception filters, and fall back strategies.
|
96
85
|
|
97
|
-
|
98
|
-
See project''s home page for usage examples and more information.
|
99
|
-
|
100
|
-
'
|
86
|
+
See project's home page for usage examples and more information.
|
101
87
|
email: abaturytski@gmail.com
|
102
88
|
executables: []
|
103
89
|
extensions: []
|
@@ -120,26 +106,25 @@ files:
|
|
120
106
|
homepage: https://github.com/aliakb/attempt_this
|
121
107
|
licenses:
|
122
108
|
- MIT
|
109
|
+
metadata: {}
|
123
110
|
post_install_message:
|
124
111
|
rdoc_options: []
|
125
112
|
require_paths:
|
126
113
|
- lib
|
127
114
|
required_ruby_version: !ruby/object:Gem::Requirement
|
128
|
-
none: false
|
129
115
|
requirements:
|
130
|
-
- -
|
116
|
+
- - '>='
|
131
117
|
- !ruby/object:Gem::Version
|
132
118
|
version: '0'
|
133
119
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
134
|
-
none: false
|
135
120
|
requirements:
|
136
|
-
- -
|
121
|
+
- - '>='
|
137
122
|
- !ruby/object:Gem::Version
|
138
123
|
version: '0'
|
139
124
|
requirements: []
|
140
125
|
rubyforge_project:
|
141
|
-
rubygems_version:
|
126
|
+
rubygems_version: 2.0.3
|
142
127
|
signing_key:
|
143
|
-
specification_version:
|
128
|
+
specification_version: 4
|
144
129
|
summary: Retry policy mix-in
|
145
130
|
test_files: []
|