take2 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/ISSUE_TEMPLATE/bug_report.md +24 -0
- data/.github/ISSUE_TEMPLATE/feature_request.md +17 -0
- data/README.md +82 -1
- data/lib/take2.rb +1 -3
- data/lib/take2/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 93023dc58265f6607decc8cb6aa621c3ac538752
|
4
|
+
data.tar.gz: 99d85d1401815f441b891ac84468dac5cce4860e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d38f2b5982925c8d4a116b14d799e8deb93256bccd886cc0dd0a560eed664f0caf8d5ba158074d15fc9ae2f54df33592b473af0f5611e2f19fba4a4281902d3d
|
7
|
+
data.tar.gz: 34fb1713275927a3edeee00870331f8e44b182ac1da2dcd0238e5c459f86839b8e03424224da3be84a0c0a472b7aa7de937febd9a3e7006c7da00a28860b3741
|
@@ -0,0 +1,24 @@
|
|
1
|
+
---
|
2
|
+
name: Bug report
|
3
|
+
about: Create a report to help us improve
|
4
|
+
|
5
|
+
---
|
6
|
+
|
7
|
+
**Describe the bug**
|
8
|
+
A clear and concise description of what the bug is.
|
9
|
+
|
10
|
+
**To Reproduce**
|
11
|
+
Steps to reproduce the behavior:
|
12
|
+
1. Go to '...'
|
13
|
+
2. Click on '....'
|
14
|
+
3. Scroll down to '....'
|
15
|
+
4. See error
|
16
|
+
|
17
|
+
**Expected behavior**
|
18
|
+
A clear and concise description of what you expected to happen.
|
19
|
+
|
20
|
+
**Screenshots**
|
21
|
+
If applicable, add screenshots to help explain your problem.
|
22
|
+
|
23
|
+
**Additional context**
|
24
|
+
Add any other context about the problem here.
|
@@ -0,0 +1,17 @@
|
|
1
|
+
---
|
2
|
+
name: Feature request
|
3
|
+
about: Suggest an idea for this project
|
4
|
+
|
5
|
+
---
|
6
|
+
|
7
|
+
**Is your feature request related to a problem? Please describe.**
|
8
|
+
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
9
|
+
|
10
|
+
**Describe the solution you'd like**
|
11
|
+
A clear and concise description of what you want to happen.
|
12
|
+
|
13
|
+
**Describe alternatives you've considered**
|
14
|
+
A clear and concise description of any alternative solutions or features you've considered.
|
15
|
+
|
16
|
+
**Additional context**
|
17
|
+
Add any other context or screenshots about the feature request here.
|
data/README.md
CHANGED
@@ -1 +1,82 @@
|
|
1
|
-
|
1
|
+
## Take2
|
2
|
+
#
|
3
|
+
Define rules for retrying behavior.
|
4
|
+
Yield block of code into the public api of the take2.
|
5
|
+
Things getting take two :)
|
6
|
+
|
7
|
+
## Install
|
8
|
+
#
|
9
|
+
```
|
10
|
+
gem install take2
|
11
|
+
```
|
12
|
+
## Examples
|
13
|
+
#
|
14
|
+
```
|
15
|
+
class KratosService
|
16
|
+
include Take2
|
17
|
+
|
18
|
+
|
19
|
+
number_of_retries 3
|
20
|
+
|
21
|
+
# Could be configured globally or on class level.
|
22
|
+
retriable_errors Net::HTTPRetriableError, Net::HTTPServerError
|
23
|
+
|
24
|
+
# Retry unless the response status is 5xx. The implementation is dependent of the http lib in use.
|
25
|
+
retriable_condition proc { |error| error.response.code < 500 }
|
26
|
+
|
27
|
+
# Defines callable code to run before next retry. Could be an out put to some logger.
|
28
|
+
on_retry proc { |error, tries| puts "#{self.name} - Retrying.. #{tries} of #{self.retriable_configuration[:retries]} (#{error})" }
|
29
|
+
|
30
|
+
sleep_before_retry 3.3
|
31
|
+
|
32
|
+
def call_boy
|
33
|
+
call_api_with_retry do
|
34
|
+
# Some logic that might raise..
|
35
|
+
# If it will raise retriable, magic happens.
|
36
|
+
# If not the original error re raised
|
37
|
+
|
38
|
+
raise Net::HTTPRetriableError.new 'Release the Kraken...many times!!', nil
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
KratosService.new.call_boy =>
|
45
|
+
KratosService - Retrying.. 3 of 3 (Release the Kraken...many times!!)
|
46
|
+
KratosService - Retrying.. 2 of 3 (Release the Kraken...many times!!)
|
47
|
+
KratosService - Retrying.. 1 of 3 (Release the Kraken...many times!!)
|
48
|
+
# After the retrying is done, original error re-raised
|
49
|
+
Net::HTTPRetriableError: Release the Kraken...many times!!
|
50
|
+
|
51
|
+
# Not wrapping with method
|
52
|
+
KratosService.new.call_api_with_retry { 1 / 0 }
|
53
|
+
|
54
|
+
# Or..
|
55
|
+
Class.new { include Take2 }.new.call_api_with_retry { 1 / 0 }
|
56
|
+
|
57
|
+
|
58
|
+
# Current configuration hash
|
59
|
+
KratosService.retriable_configuration
|
60
|
+
|
61
|
+
```
|
62
|
+
|
63
|
+
## Configurations
|
64
|
+
#### could be implemented as rails initializer
|
65
|
+
#
|
66
|
+
```
|
67
|
+
# config/initializers/take2.rb
|
68
|
+
|
69
|
+
Take2.configure do |config|
|
70
|
+
config.retries = 3
|
71
|
+
config.retriable = [
|
72
|
+
Net::HTTPServerError,
|
73
|
+
Net::HTTPServerException,
|
74
|
+
Net::HTTPRetriableError,
|
75
|
+
Errno::ECONNRESET,
|
76
|
+
IOError
|
77
|
+
].freeze
|
78
|
+
config.retry_condition_proc = proc {false}
|
79
|
+
config.time_to_sleep = nil
|
80
|
+
config.retry_proc = proc {Rails.logger.info "Retry message"}
|
81
|
+
end
|
82
|
+
```
|
data/lib/take2.rb
CHANGED
@@ -39,9 +39,7 @@ module Take2
|
|
39
39
|
# number_of_retries 3
|
40
40
|
# retriable_errors Net::HTTPRetriableError, Net::HTTPServerError
|
41
41
|
# retriable_condition proc { |error| response_status(error.response) < 500 }
|
42
|
-
# on_retry proc
|
43
|
-
# puts "#{self.class.name} - Retrying.. #{tries} of #{self.class.retriable_configuration[:retries]} (#{error})"
|
44
|
-
# end
|
42
|
+
# on_retry proc { |error, tries| puts "#{self.name} - Retrying.. #{tries} of #{self.retriable_configuration[:retries]} (#{error})" }
|
45
43
|
# sleep_before_retry 3
|
46
44
|
#
|
47
45
|
# def give_me_food
|
data/lib/take2/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: take2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anton Magids
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-09-
|
11
|
+
date: 2018-09-13 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Easily define Take2 / retry behavior for API wrappers, service objects
|
14
14
|
or a single method.
|
@@ -18,6 +18,8 @@ executables: []
|
|
18
18
|
extensions: []
|
19
19
|
extra_rdoc_files: []
|
20
20
|
files:
|
21
|
+
- ".github/ISSUE_TEMPLATE/bug_report.md"
|
22
|
+
- ".github/ISSUE_TEMPLATE/feature_request.md"
|
21
23
|
- ".gitignore"
|
22
24
|
- CHANGELOG.md
|
23
25
|
- Gemfile
|