semian 0.11.2 → 0.11.6

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
  SHA256:
3
- metadata.gz: 8b31af83f6a9733b9a9a4ce8743aa6f0f8e12a02be8ea93769a3104793ca5403
4
- data.tar.gz: 387524ab30d95ccf7f7b0fac73fdabf8af3dbfb34b61ec28778a90abc7230a9a
3
+ metadata.gz: 22a30223a7af05c3b0cb5d06422bb2a9b9463b74fda1a1e919636225c7f5b24e
4
+ data.tar.gz: e84f349ce5324c0148f922248850c0ef9c04796640bbec8ed24fe108845492d7
5
5
  SHA512:
6
- metadata.gz: bda9c43cd95f0d6ed7c0cda4507ed855a5c4c06cc7586d705da1c6f6660077cc1af14e52a7f80f62b6a376da67f458fc119899aa56062c643a0decac4194ce65
7
- data.tar.gz: 8e9cacebf59371bf6b683dbf64c348ec654ebfdc8bf47a4b6f2f6ac328c39911fe2b3477adccd4004ff3eeb14798ac9528cad3d7c0c4501c51cebcf69c175929
6
+ metadata.gz: 25d16269de608362228ad8153a4056d6b46c6860a4d129417e655eef218d9fd9957f3572757b77ae0e85884db2bedf8bbf35319dac4459d9209853830d7abe51
7
+ data.tar.gz: e75d7b07c99fe4546baa88a0ee89cc09bad4cfbbae9a311b1a012022a90c72683017f00536758d3073e900fa3b2f0ef203549acf793cfd633a20201306003d74
@@ -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 ((TYPE(tickets) == T_NIL && TYPE(quota) == T_NIL) ||(TYPE(tickets) != T_NIL && TYPE(quota) != T_NIL)){
271
- rb_raise(rb_eArgError, "Must pass exactly one of ticket or quota");
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
 
@@ -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
 
@@ -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)
@@ -1,3 +1,3 @@
1
1
  module Semian
2
- VERSION = '0.11.2'
2
+ VERSION = '0.11.6'
3
3
  end
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 ciruit will transition in the half-open state.
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 successulf acquisitions of the resource it will transition back to the closed state.
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 number of errors that will trigger the circuit opening. (circuit breaker required)
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.2
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-01-27 00:00:00.000000000 Z
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.0.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