semian 0.11.4 → 0.11.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ext/semian/resource.c +5 -2
- data/lib/semian/circuit_breaker.rb +3 -2
- data/lib/semian/net_http.rb +10 -1
- data/lib/semian/redis.rb +8 -0
- data/lib/semian/version.rb +1 -1
- data/lib/semian.rb +3 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b5e836c65bee18b5d62d92e165cd34c9beafa0d42c2c408138594d3720abb4d
|
4
|
+
data.tar.gz: 9ba054d5523c916729b2438cefad336305a1ec6818c57a21359f0e9645579050
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 370d75f2276562f2e4b0fda0732a0f2d9faa84259fd0ca8fb1f3eb4e11be98550e17f1dab5a9258333240f0db48316df6115b5e5b184344f2ec3f4438e421c37
|
7
|
+
data.tar.gz: d49a1d3abe581d78634986c3f735134a6d11a84721d97f8807cf205df76ee1a37e4864372927e6554826c8b5d74ca2d1286856a73a264e4e1e85c9e82c164902
|
data/ext/semian/resource.c
CHANGED
@@ -272,8 +272,11 @@ check_permissions_arg(VALUE permissions)
|
|
272
272
|
static void
|
273
273
|
check_tickets_xor_quota_arg(VALUE tickets, VALUE quota)
|
274
274
|
{
|
275
|
-
if (
|
276
|
-
rb_raise(rb_eArgError, "
|
275
|
+
if (tickets == Qnil && quota == Qnil) {
|
276
|
+
rb_raise(rb_eArgError, "Semian configuration require either the :ticket or :quota parameter, you provided neither");
|
277
|
+
}
|
278
|
+
if (tickets != Qnil && quota != Qnil) {
|
279
|
+
rb_raise(rb_eArgError, "Semian configuration require either the :ticket or :quota parameter, you provided both");
|
277
280
|
}
|
278
281
|
}
|
279
282
|
|
@@ -7,10 +7,11 @@ module Semian
|
|
7
7
|
attr_reader :name, :half_open_resource_timeout, :error_timeout, :state, :last_error
|
8
8
|
|
9
9
|
def initialize(name, exceptions:, success_threshold:, error_threshold:,
|
10
|
-
error_timeout:, implementation:, half_open_resource_timeout: nil)
|
10
|
+
error_timeout:, implementation:, half_open_resource_timeout: nil, error_threshold_timeout: nil)
|
11
11
|
@name = name.to_sym
|
12
12
|
@success_count_threshold = success_threshold
|
13
13
|
@error_count_threshold = error_threshold
|
14
|
+
@error_threshold_timeout = error_threshold_timeout || error_timeout
|
14
15
|
@error_timeout = error_timeout
|
15
16
|
@exceptions = exceptions
|
16
17
|
@half_open_resource_timeout = half_open_resource_timeout
|
@@ -124,7 +125,7 @@ module Semian
|
|
124
125
|
end
|
125
126
|
|
126
127
|
def push_time(window, time: Time.now)
|
127
|
-
window.reject! { |err_time| err_time + @
|
128
|
+
window.reject! { |err_time| err_time + @error_threshold_timeout < time.to_i }
|
128
129
|
window << time.to_i
|
129
130
|
end
|
130
131
|
|
data/lib/semian/net_http.rb
CHANGED
@@ -43,6 +43,14 @@ module Semian
|
|
43
43
|
::SystemCallError, # includes ::Errno::EINVAL, ::Errno::ECONNRESET, ::Errno::ECONNREFUSED, ::Errno::ETIMEDOUT, and more
|
44
44
|
].freeze # Net::HTTP can throw many different errors, this tries to capture most of them
|
45
45
|
|
46
|
+
module ClassMethods
|
47
|
+
def new(*args, semian: true)
|
48
|
+
http = super(*args)
|
49
|
+
http.instance_variable_set(:@semian_enabled, semian)
|
50
|
+
http
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
46
54
|
class << self
|
47
55
|
attr_accessor :exceptions
|
48
56
|
attr_reader :semian_configuration
|
@@ -75,7 +83,7 @@ module Semian
|
|
75
83
|
end
|
76
84
|
|
77
85
|
def disabled?
|
78
|
-
raw_semian_options.nil?
|
86
|
+
raw_semian_options.nil? || @semian_enabled == false
|
79
87
|
end
|
80
88
|
|
81
89
|
def connect
|
@@ -115,3 +123,4 @@ module Semian
|
|
115
123
|
end
|
116
124
|
|
117
125
|
Net::HTTP.prepend(Semian::NetHTTP)
|
126
|
+
Net::HTTP.singleton_class.prepend(Semian::NetHTTP::ClassMethods)
|
data/lib/semian/redis.rb
CHANGED
@@ -16,6 +16,14 @@ class Redis
|
|
16
16
|
include ::Semian::AdapterError
|
17
17
|
end
|
18
18
|
|
19
|
+
class ConnectionError < Redis::BaseConnectionError
|
20
|
+
# A Connection Reset is a fast failure and we don't want to track these errors in
|
21
|
+
# semian
|
22
|
+
def marks_semian_circuits?
|
23
|
+
message != "Connection lost (ECONNRESET)"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
19
27
|
ResourceBusyError = Class.new(SemianError)
|
20
28
|
CircuitOpenError = Class.new(SemianError)
|
21
29
|
ResolveError = Class.new(SemianError)
|
data/lib/semian/version.rb
CHANGED
data/lib/semian.rb
CHANGED
@@ -46,7 +46,7 @@ require 'semian/lru_hash'
|
|
46
46
|
# resource the time to recover. If `error_threshold` errors happen in the span of `error_timeout`
|
47
47
|
# then the circuit will be opened and every attempt to acquire the resource will immediately fail.
|
48
48
|
#
|
49
|
-
# Once in open state, after `error_timeout` is elapsed, the
|
49
|
+
# Once in open state, after `error_timeout` is elapsed, the circuit will transition in the half-open state.
|
50
50
|
# In that state a single error will fully re-open the circuit, and the circuit will transition back to the closed
|
51
51
|
# state only after the resource is acquired `success_threshold` consecutive times.
|
52
52
|
#
|
@@ -62,7 +62,7 @@ require 'semian/lru_hash'
|
|
62
62
|
#
|
63
63
|
# After 3 failures in the span of 10 seconds the circuit will be open.
|
64
64
|
# After an additional 10 seconds it will transition to half-open.
|
65
|
-
# And finally after 2
|
65
|
+
# And finally after 2 successful acquisitions of the resource it will transition back to the closed state.
|
66
66
|
#
|
67
67
|
# ===== Using a resource
|
68
68
|
#
|
@@ -257,6 +257,7 @@ module Semian
|
|
257
257
|
name,
|
258
258
|
success_threshold: options[:success_threshold],
|
259
259
|
error_threshold: options[:error_threshold],
|
260
|
+
error_threshold_timeout: options[:error_threshold_timeout],
|
260
261
|
error_timeout: options[:error_timeout],
|
261
262
|
exceptions: Array(exceptions) + [::Semian::BaseError],
|
262
263
|
half_open_resource_timeout: options[:half_open_resource_timeout],
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: semian
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.11.
|
4
|
+
version: 0.11.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Scott Francis
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2022-01-12 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rake-compiler
|
@@ -251,7 +251,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
251
251
|
- !ruby/object:Gem::Version
|
252
252
|
version: '0'
|
253
253
|
requirements: []
|
254
|
-
rubygems_version: 3.
|
254
|
+
rubygems_version: 3.2.20
|
255
255
|
signing_key:
|
256
256
|
specification_version: 4
|
257
257
|
summary: Bulkheading for Ruby with SysV semaphores
|