r4r 0.1.1 → 0.1.2

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
2
  SHA1:
3
- metadata.gz: 6e8cc23b4bbeffc3de5242dd46b931fede16d2cf
4
- data.tar.gz: a8f14815d31138185257f7530d3474735f745b56
3
+ metadata.gz: 0d6643a7272b11d76ca1ad8d07062701cffa82c4
4
+ data.tar.gz: 7244f2d374c6d2d2680a79faf807bc5da68bf637
5
5
  SHA512:
6
- metadata.gz: cef0721f973c4c62dd206299c331451b280c65881e4278d6b2887bc405910b1c2efc0a9cc4694d8addd029967f034fd2cb18311f02fe5ad48f36c1b1bd7ffa8c
7
- data.tar.gz: 0e48e06286d0e6093fbaf7d66027decafe10d2fa668363c30c345362735bba7ddb45ed45abee15cce03ba5bdab20bb90e7120df958ec31cc5268fc1166b69899
6
+ metadata.gz: d85b7fb04f29bc17c742ec0cdea068fee2f250722f9256cceac200f275ff88375dec86868986072ca5e4dc00868dafc6d03d56d77ad487a83ddd105013eaab69
7
+ data.tar.gz: df29416b7c07ed01297765d99436de81c95a806a87bd95fc17d07615b6dcb2debc8830cc4ed946fd3ce3c758008fbdf2e9f621748ab839922077558f7b12f74d
data/.circleci/config.yml CHANGED
@@ -7,22 +7,11 @@ shared_ghpages: &shared_ghpages
7
7
 
8
8
  steps:
9
9
  - checkout
10
- # Download and cache dependencies
11
- - restore_cache:
12
- keys:
13
- - v1-dependencies-{{ .Environment.CIRCLE_STAGE }}-{{ checksum "Gemfile.lock" }}
14
- - v1-dependencies-
15
-
16
10
  - run:
17
11
  name: install dependencies
18
12
  command: |
19
13
  bundle install --jobs=4 --retry=3 --path vendor/bundle
20
14
 
21
- - save_cache:
22
- paths:
23
- - ./vendor/bundle
24
- key: v1-dependencies-{{ .Environment.CIRCLE_STAGE }}-{{ checksum "Gemfile.lock" }}
25
-
26
15
  - add-ssh-keys:
27
16
  fingerprints:
28
17
  - "af:38:77:24:f4:c6:33:f2:74:60:e5:cc:76:0e:a7:ad"
@@ -42,21 +31,11 @@ shared_ruby_build: &shared_ruby_build
42
31
  steps:
43
32
  - checkout
44
33
  # Download and cache dependencies
45
- - restore_cache:
46
- keys:
47
- - v1-dependencies-{{ .Environment.CIRCLE_STAGE }}-{{ checksum "Gemfile.lock" }}
48
- - v1-dependencies-
49
-
50
34
  - run:
51
35
  name: install dependencies
52
36
  command: |
53
37
  bundle install --jobs=4 --retry=3 --path vendor/bundle
54
38
 
55
- - save_cache:
56
- paths:
57
- - ./vendor/bundle
58
- key: v1-dependencies-{{ .Environment.CIRCLE_STAGE }}-{{ checksum "Gemfile.lock" }}
59
-
60
39
  - run:
61
40
  name: compile
62
41
  command: |
@@ -88,10 +67,14 @@ jobs:
88
67
  <<: *shared_ruby_build
89
68
  docker:
90
69
  - image: ruby:2.4
70
+ ruby25:
71
+ <<: *shared_ruby_build
72
+ docker:
73
+ - image: ruby:2.5
91
74
  ghpages:
92
75
  <<: *shared_ghpages
93
76
  docker:
94
- - image: ruby:2.4
77
+ - image: ruby:2.5
95
78
 
96
79
  workflows:
97
80
  version: 2
@@ -99,10 +82,12 @@ workflows:
99
82
  jobs:
100
83
  - ruby22
101
84
  - ruby24
85
+ - ruby25
102
86
  - ghpages:
103
87
  requires:
104
88
  - ruby22
105
89
  - ruby24
90
+ - ruby25
106
91
  filters:
107
92
  branches:
108
93
  only: master
data/.gitignore CHANGED
@@ -10,3 +10,4 @@
10
10
  /html/
11
11
  /test/reports/
12
12
  /docs/
13
+ Gemfile.lock
data/bin/ghpages CHANGED
@@ -1,9 +1,10 @@
1
1
  #!/bin/bash
2
2
 
3
- set -ex
3
+ set -e
4
4
 
5
5
  git diff-index --quiet HEAD -- || (
6
6
  echo "Uncommitted changes detected"
7
+ git diff-index HEAD
7
8
  exit 1
8
9
  )
9
10
 
@@ -0,0 +1,34 @@
1
+ module R4r
2
+ # An error raises when retry was failed.
3
+ #
4
+ class NonRetriableError < RuntimeError
5
+ attr_reader :cause
6
+
7
+ KIND_LIMIT_REACHED = 0
8
+ KIND_REJECTED_BY_POLICY = 1
9
+ KIND_BUDGET_EXHAUSTED = 2
10
+
11
+ # @param [String] message an error message
12
+ # @param [Exception] cause a error cause
13
+ def initialize(message:, kind:, cause:)
14
+ super(message)
15
+ @cause = cause
16
+ @kind = kind
17
+ end
18
+
19
+ # Is error limit reached
20
+ def limit_reached?
21
+ @kind == KIND_LIMIT_REACHED
22
+ end
23
+
24
+ # Is error was rejected by policy
25
+ def rejected_by_policy?
26
+ @kind == KIND_REJECTED_BY_POLICY
27
+ end
28
+
29
+ # Is error budget exhausted
30
+ def budget_exhausted?
31
+ @kind == KIND_BUDGET_EXHAUSTED
32
+ end
33
+ end
34
+ end
data/lib/r4r/retry.rb CHANGED
@@ -1,18 +1,4 @@
1
1
  module R4r
2
-
3
- # An error raises when retry was failed.
4
- #
5
- class NonRetriableError < RuntimeError
6
- attr_reader :cause
7
-
8
- # @param [String] message an error message
9
- # @param [Exception] cause a error cause
10
- def initialize(message:, cause:)
11
- super(message)
12
- @cause = cause
13
- end
14
- end
15
-
16
2
  # Decorator that wrap blocks and call it within retries.
17
3
  #
18
4
  # @attr [Array[Float]] backoff
@@ -72,15 +58,27 @@ module R4r
72
58
  raise err if err.is_a?(NonRetriableError)
73
59
 
74
60
  if (num_retry + 1 == @backoff.size)
75
- raise NonRetriableError.new(message: "Retry limit [#{@backoff.size}] reached: #{err}", cause: err)
61
+ raise NonRetriableError.new(
62
+ message: "Retry limit [#{@backoff.size}] reached: #{err}",
63
+ kind: NonRetriableError::KIND_LIMIT_REACHED,
64
+ cause: err
65
+ )
76
66
  end
77
67
 
78
68
  unless @policy.call(error: err, num_retry: num_retry)
79
- raise NonRetriableError.new(message: "An error was rejected by policy: #{err}", cause: err)
69
+ raise NonRetriableError.new(
70
+ message: "An error was rejected by policy: #{err}",
71
+ kind: NonRetriableError::KIND_REJECTED_BY_POLICY,
72
+ cause: err
73
+ )
80
74
  end
81
75
 
82
76
  unless @budget.try_withdraw
83
- raise NonRetriableError.new(message: "Budget was exhausted: #{err}", cause: err)
77
+ raise NonRetriableError.new(
78
+ message: "Budget was exhausted: #{err}",
79
+ kind: NonRetriableError::KIND_BUDGET_EXHAUSTED,
80
+ cause: err
81
+ )
84
82
  end
85
83
  end
86
84
 
data/lib/r4r/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module R4r
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
data/lib/r4r.rb CHANGED
@@ -9,9 +9,7 @@ require "r4r/ring_bits"
9
9
  require "r4r/windowed_adder"
10
10
  require "r4r/token_bucket"
11
11
 
12
+ require 'r4r/non_retriable_error'
12
13
  require "r4r/retry_budget"
13
14
  require "r4r/retry_policy"
14
15
  require "r4r/retry"
15
-
16
- module R4r
17
- end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: r4r
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Galinsky
@@ -120,7 +120,6 @@ files:
120
120
  - ".circleci/config.yml"
121
121
  - ".gitignore"
122
122
  - Gemfile
123
- - Gemfile.lock
124
123
  - LICENSE.txt
125
124
  - README.md
126
125
  - Rakefile
@@ -134,6 +133,7 @@ files:
134
133
  - ext/r4r/system_clock_ext/system_clock_ext.c
135
134
  - lib/r4r.rb
136
135
  - lib/r4r/clock.rb
136
+ - lib/r4r/non_retriable_error.rb
137
137
  - lib/r4r/retry.rb
138
138
  - lib/r4r/retry_budget.rb
139
139
  - lib/r4r/retry_policy.rb
data/Gemfile.lock DELETED
@@ -1,39 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- r4r (0.1.0)
5
-
6
- GEM
7
- remote: https://rubygems.org/
8
- specs:
9
- ansi (1.5.0)
10
- builder (3.2.3)
11
- minitest (5.10.3)
12
- minitest-ci (3.3.0)
13
- minitest (>= 5.0.6)
14
- minitest-reporters (1.1.19)
15
- ansi
16
- builder
17
- minitest (>= 5.0)
18
- ruby-progressbar
19
- rake (11.3.0)
20
- rake-compiler (1.0.4)
21
- rake
22
- ruby-progressbar (1.9.0)
23
- yard (0.9.12)
24
-
25
- PLATFORMS
26
- ruby
27
-
28
- DEPENDENCIES
29
- bundler (~> 1.15)
30
- minitest (~> 5.0)
31
- minitest-ci (~> 3.3)
32
- minitest-reporters (~> 1.1)
33
- r4r!
34
- rake (~> 11.0)
35
- rake-compiler (~> 1.0)
36
- yard (~> 0.9)
37
-
38
- BUNDLED WITH
39
- 1.16.0