evt-retry 0.1.1.1 → 0.1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 1495a2bf15a42bb71df5cd296f52c93ba5473bf8
4
- data.tar.gz: c6d06ffab206303c1eefe530cd73ad1322709700
2
+ SHA256:
3
+ metadata.gz: ead5a0d5b48258bfa2e98064a2c647fa6acf795149b68ec7ea73d94756b5b97f
4
+ data.tar.gz: 1d9aae6ee82c7dd3d38f3f102abc9a595e8eddd25fd0ff99a67d13b9b1610fee
5
5
  SHA512:
6
- metadata.gz: 24f805eabce15ce685af0182a0c7a542abf3e8836727e2f781e7e94a417f0054b8e5effc13d68444cd333af6be6265620196d7f5b5f43de70bfd571cf1d46fc9
7
- data.tar.gz: c568352d2e6e0c6d7c2021bc42973ccba512f9a8bf6690ee3c040669922dfc0a3eb6361aa6a6fdf436170c573bed347d2f5a664a9c7ee598616683bd8c70c62d
6
+ metadata.gz: 4c2af64e361bd3c9d50cedda46d6cdd598c28340c1aa1ab5b6141faf2db2070d48544f883d1a3133dc60b7494b3003cc9b7497595ef62a9746980a1a1f8a3fce
7
+ data.tar.gz: 532d792246a1b2980e57f2dafc07ea42db7f0c5cf63e752f25beb565211398b6a656b5cb20e93c4da90a3b45833aaa9a244977df7c2378d078fbf3f4892a8210
@@ -0,0 +1,15 @@
1
+ class Retry
2
+ module Controls
3
+ module Dependency
4
+ def self.example
5
+ Example.new
6
+ end
7
+
8
+ class Example
9
+ include Dependency
10
+
11
+ dependency :rtry, Retry
12
+ end
13
+ end
14
+ end
15
+ end
@@ -1,6 +1,6 @@
1
1
  class Retry
2
2
  module Controls
3
- ErrorA = Try::Controls::ErrorA
4
- ErrorB = Try::Controls::ErrorB
3
+ ErrorA = Class.new(RuntimeError)
4
+ ErrorB = Class.new(RuntimeError)
5
5
  end
6
6
  end
@@ -0,0 +1,14 @@
1
+ class Retry
2
+ module Controls
3
+ module Receiver
4
+ def self.example
5
+ Example.new
6
+ end
7
+
8
+ class Example
9
+ attr_accessor :rtry
10
+ attr_accessor :other_retry
11
+ end
12
+ end
13
+ end
14
+ end
@@ -2,3 +2,5 @@ require 'try/controls'
2
2
 
3
3
  require 'retry/controls/error'
4
4
  require 'retry/controls/time'
5
+ require 'retry/controls/receiver'
6
+ require 'retry/controls/dependency'
data/lib/retry/retry.rb CHANGED
@@ -1,10 +1,6 @@
1
1
  class Retry
2
- initializer :errors
3
-
4
- def millisecond_intervals
5
- @millisecond_intervals ||= [0].to_enum
6
- end
7
- attr_writer :millisecond_intervals
2
+ include ::Telemetry::Dependency
3
+ extend Retry::Telemetry::Register
8
4
 
9
5
  def action_executed(&action)
10
6
  unless action.nil?
@@ -15,25 +11,35 @@ class Retry
15
11
  end
16
12
  attr_writer :action_executed
17
13
 
18
- def self.build(*errors, millisecond_intervals: nil)
19
- instance = new(errors)
20
- instance.millisecond_intervals = millisecond_intervals&.to_enum
14
+ def self.build
15
+ new
16
+ end
17
+
18
+ def self.configure(receiver, attr_name: nil)
19
+ attr_name ||= :rtry
20
+ instance = build
21
+ receiver.public_send("#{attr_name}=", instance)
21
22
  instance
22
23
  end
23
24
 
24
25
  def self.call(*errors, millisecond_intervals: nil, &action)
25
- instance = build(*errors, millisecond_intervals: millisecond_intervals)
26
- instance.(&action)
26
+ instance = build
27
+ instance.(errors, millisecond_intervals: millisecond_intervals, &action)
27
28
  end
28
29
 
29
- def call(&action)
30
+ def call(*errors, millisecond_intervals: nil, &action)
31
+ errors = errors.flatten
32
+ millisecond_intervals ||= [0]
33
+
34
+ intervals = millisecond_intervals.to_enum
35
+
30
36
  retries = 0
31
37
 
32
38
  error = nil
33
39
  probe = proc { |e| error = e }
34
40
 
35
41
  loop do
36
- success = Try.(*errors, error_probe: probe) do
42
+ success = Try.(errors, error_probe: probe) do
37
43
  action.call(retries)
38
44
  end
39
45
 
@@ -43,7 +49,10 @@ class Retry
43
49
 
44
50
  retries += 1
45
51
 
46
- interval = millisecond_intervals.next
52
+ interval = intervals.next
53
+
54
+ telemetry.record :retried, Retry::Telemetry::Data.new(retries, error.class, interval)
55
+
47
56
  break if interval.nil?
48
57
 
49
58
  sleep (interval/1000.0)
@@ -0,0 +1,14 @@
1
+ class Retry
2
+ module Substitute
3
+ def self.build
4
+ instance = Retry.new()
5
+ sink = Retry.register_telemetry_sink(instance)
6
+ instance.sink = sink
7
+ instance
8
+ end
9
+
10
+ class Retry < ::Retry
11
+ attr_accessor :sink
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,23 @@
1
+ class Retry
2
+ module Telemetry
3
+ class Sink
4
+ include ::Telemetry::Sink
5
+
6
+ record :retried
7
+ end
8
+
9
+ Data = Struct.new :retry, :error, :millisecond_interval
10
+
11
+ def self.sink
12
+ Sink.new
13
+ end
14
+
15
+ module Register
16
+ def register_telemetry_sink(rtry)
17
+ sink = Retry::Telemetry.sink
18
+ rtry.telemetry.register(sink)
19
+ sink
20
+ end
21
+ end
22
+ end
23
+ end
data/lib/retry.rb CHANGED
@@ -1,4 +1,8 @@
1
1
  require 'try'
2
2
  require 'initializer'; Initializer.activate
3
+ require 'dependency'; Dependency.activate
4
+ require 'telemetry'
3
5
 
6
+ require 'retry/substitute'
7
+ require 'retry/telemetry'
4
8
  require 'retry/retry'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: evt-retry
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1.1
4
+ version: 0.1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - The Eventide Project
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-01 00:00:00.000000000 Z
11
+ date: 2018-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: evt-try
@@ -38,6 +38,34 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: evt-dependency
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: evt-telemetry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
41
69
  - !ruby/object:Gem::Dependency
42
70
  name: test_bench
43
71
  requirement: !ruby/object:Gem::Requirement
@@ -60,9 +88,13 @@ extra_rdoc_files: []
60
88
  files:
61
89
  - lib/retry.rb
62
90
  - lib/retry/controls.rb
91
+ - lib/retry/controls/dependency.rb
63
92
  - lib/retry/controls/error.rb
93
+ - lib/retry/controls/receiver.rb
64
94
  - lib/retry/controls/time.rb
65
95
  - lib/retry/retry.rb
96
+ - lib/retry/substitute.rb
97
+ - lib/retry/telemetry.rb
66
98
  homepage: https://github.com/eventide-project/retry
67
99
  licenses:
68
100
  - MIT
@@ -83,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
115
  version: '0'
84
116
  requirements: []
85
117
  rubyforge_project:
86
- rubygems_version: 2.6.11
118
+ rubygems_version: 2.7.3
87
119
  signing_key:
88
120
  specification_version: 4
89
121
  summary: Retry an execution that terminates with an error