semian 0.11.2 → 0.11.6
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 +10 -2
- data/ext/semian/resource.h +3 -3
- data/lib/semian/circuit_breaker.rb +4 -0
- data/lib/semian/net_http.rb +10 -1
- data/lib/semian/version.rb +1 -1
- data/lib/semian.rb +4 -3
- 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: 22a30223a7af05c3b0cb5d06422bb2a9b9463b74fda1a1e919636225c7f5b24e
|
4
|
+
data.tar.gz: e84f349ce5324c0148f922248850c0ef9c04796640bbec8ed24fe108845492d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 25d16269de608362228ad8153a4056d6b46c6860a4d129417e655eef218d9fd9957f3572757b77ae0e85884db2bedf8bbf35319dac4459d9209853830d7abe51
|
7
|
+
data.tar.gz: e75d7b07c99fe4546baa88a0ee89cc09bad4cfbbae9a311b1a012022a90c72683017f00536758d3073e900fa3b2f0ef203549acf793cfd633a20201306003d74
|
data/ext/semian/resource.c
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
#include "resource.h"
|
2
2
|
|
3
|
+
// Ruby variables
|
4
|
+
ID id_wait_time;
|
5
|
+
ID id_timeout;
|
6
|
+
int system_max_semaphore_count;
|
7
|
+
|
3
8
|
static VALUE
|
4
9
|
cleanup_semian_resource_acquire(VALUE self);
|
5
10
|
|
@@ -267,8 +272,11 @@ check_permissions_arg(VALUE permissions)
|
|
267
272
|
static void
|
268
273
|
check_tickets_xor_quota_arg(VALUE tickets, VALUE quota)
|
269
274
|
{
|
270
|
-
if (
|
271
|
-
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");
|
272
280
|
}
|
273
281
|
}
|
274
282
|
|
data/ext/semian/resource.h
CHANGED
@@ -10,9 +10,9 @@ Functions here are associated with rubyland operations.
|
|
10
10
|
#include "sysv_semaphores.h"
|
11
11
|
|
12
12
|
// Ruby variables
|
13
|
-
ID id_wait_time;
|
14
|
-
ID id_timeout;
|
15
|
-
int system_max_semaphore_count;
|
13
|
+
extern ID id_wait_time;
|
14
|
+
extern ID id_timeout;
|
15
|
+
extern int system_max_semaphore_count;
|
16
16
|
|
17
17
|
/*
|
18
18
|
* call-seq:
|
@@ -136,6 +136,10 @@ module Semian
|
|
136
136
|
str << " success_count_threshold=#{@success_count_threshold} error_count_threshold=#{@error_count_threshold}"
|
137
137
|
str << " error_timeout=#{@error_timeout} error_last_at=\"#{@errors.last}\""
|
138
138
|
str << " name=\"#{@name}\""
|
139
|
+
if new_state == :open && @last_error
|
140
|
+
str << " last_error_message=#{@last_error.message.inspect}"
|
141
|
+
end
|
142
|
+
|
139
143
|
Semian.logger.info(str)
|
140
144
|
end
|
141
145
|
|
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/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
|
#
|
@@ -143,7 +143,8 @@ module Semian
|
|
143
143
|
#
|
144
144
|
# +timeout+: Default timeout in seconds. Default 0. (bulkhead)
|
145
145
|
#
|
146
|
-
# +error_threshold+: The
|
146
|
+
# +error_threshold+: The amount of errors that must happen within error_timeout amount of time to open
|
147
|
+
# the circuit. (circuit breaker required)
|
147
148
|
#
|
148
149
|
# +error_timeout+: The duration in seconds since the last error after which the error count is reset to 0.
|
149
150
|
# (circuit breaker required)
|
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.6
|
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: 2021-
|
13
|
+
date: 2021-12-06 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
|