easy_retry 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/lib/easy_retry.rb +24 -0
- metadata +45 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8d0c5f57e2df92f7dbaefc2db88edb0eae518174d81a1acf3bee935665e75148
|
4
|
+
data.tar.gz: f355e2390456976dca6fee9eeb64b9aa4f8922ea6bc1ba9449bce6390d950955
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 53353455650980d0b906e8d356dd21b574fe77a5fcb5c2bd941f2a3dcdfb57f882f61f181eda3003bb8ac47ecfb146033e06ea9ae526be67facdfc059599c04b
|
7
|
+
data.tar.gz: 8fe1b2482c391c22fd1d92dc3035e60c96c37792f5926073d8a0d3780ad9858a68a6288c28b0e4d7c34398d3c25f5f6b6361b92fa1f649dca845d507846a084b
|
data/lib/easy_retry.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
class Numeric
|
2
|
+
def tries(rescue_from: [StandardError])
|
3
|
+
raise ArgumentError, 'No block given' unless block_given?
|
4
|
+
|
5
|
+
max_retry = self
|
6
|
+
current_try = 1
|
7
|
+
|
8
|
+
loop do
|
9
|
+
yield(current_try)
|
10
|
+
|
11
|
+
break
|
12
|
+
rescue *rescue_from => error
|
13
|
+
Rails.logger.error "Error: #{error.message} (#{current_try}/#{max_retry})"
|
14
|
+
|
15
|
+
sleep (current_try * current_try).seconds
|
16
|
+
|
17
|
+
current_try += 1
|
18
|
+
|
19
|
+
raise error if current_try > max_retry
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
alias try tries
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: easy_retry
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Robin Goudeketting
|
8
|
+
- Peter Duijnstee
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2022-11-16 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Easily retry a block of code a predetermined number of times
|
15
|
+
email:
|
16
|
+
- r.goudeketting@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- lib/easy_retry.rb
|
22
|
+
homepage: https://github.com/goudekettingrm
|
23
|
+
licenses:
|
24
|
+
- MIT
|
25
|
+
metadata: {}
|
26
|
+
post_install_message:
|
27
|
+
rdoc_options: []
|
28
|
+
require_paths:
|
29
|
+
- lib
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirements: []
|
41
|
+
rubygems_version: 3.2.26
|
42
|
+
signing_key:
|
43
|
+
specification_version: 4
|
44
|
+
summary: Easily retry a block of code a predetermined number of times
|
45
|
+
test_files: []
|