semian 0.10.4 → 0.11.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
  SHA256:
3
- metadata.gz: e66732f3eff2bf185bafb6e8415d04bb49a946a9da90e497063c325c76361997
4
- data.tar.gz: 05bd964a1d2760b4e9d7274732f3bf31d7e788f8cffb198a5c1715ace826a85d
3
+ metadata.gz: 8b31af83f6a9733b9a9a4ce8743aa6f0f8e12a02be8ea93769a3104793ca5403
4
+ data.tar.gz: 387524ab30d95ccf7f7b0fac73fdabf8af3dbfb34b61ec28778a90abc7230a9a
5
5
  SHA512:
6
- metadata.gz: 2a94a193f5c90761c3a07bee03f8a28bcff5ad76fb36dcaba07499982fccbf5170f4fd552b9b56fc4e6ae73295f36134c4fbf87db627ebd75df72cd53f8ee77b
7
- data.tar.gz: ad6d78abed72e04575bf33e50e795e940112c2ee97bf573cec706c7111b59afe682cc549e8dbb2dbd8b3a5de8a1efa8eb1bfb3b6aa57f9f72b269153c77bf311
6
+ metadata.gz: bda9c43cd95f0d6ed7c0cda4507ed855a5c4c06cc7586d705da1c6f6660077cc1af14e52a7f80f62b6a376da67f458fc119899aa56062c643a0decac4194ce65
7
+ data.tar.gz: 8e9cacebf59371bf6b683dbf64c348ec654ebfdc8bf47a4b6f2f6ac328c39911fe2b3477adccd4004ff3eeb14798ac9528cad3d7c0c4501c51cebcf69c175929
@@ -1,5 +1,7 @@
1
1
  #include "semian.h"
2
2
 
3
+ VALUE eSyscall, eTimeout, eInternal;
4
+
3
5
  void Init_semian()
4
6
  {
5
7
  VALUE cSemian, cResource;
@@ -22,12 +24,14 @@ void Init_semian()
22
24
  * Represents a Semian error that was caused by an underlying syscall failure.
23
25
  */
24
26
  eSyscall = rb_const_get(cSemian, rb_intern("SyscallError"));
27
+ rb_global_variable(&eSyscall);
25
28
 
26
29
  /* Document-class: Semian::TimeoutError
27
30
  *
28
31
  * Raised when a Semian operation timed out.
29
32
  */
30
33
  eTimeout = rb_const_get(cSemian, rb_intern("TimeoutError"));
34
+ rb_global_variable(&eTimeout);
31
35
 
32
36
  /* Document-class: Semian::InternalError
33
37
  *
@@ -40,6 +44,7 @@ void Init_semian()
40
44
  * the semaphore in this case.
41
45
  */
42
46
  eInternal = rb_const_get(cSemian, rb_intern("InternalError"));
47
+ rb_global_variable(&eInternal);
43
48
 
44
49
  rb_define_alloc_func(cResource, semian_resource_alloc);
45
50
  rb_define_method(cResource, "initialize_semaphore", semian_resource_initialize, 5);
@@ -63,7 +63,7 @@ enum SEMINDEX_ENUM {
63
63
  FOREACH_SEMINDEX(GENERATE_ENUM)
64
64
  };
65
65
 
66
- VALUE eSyscall, eTimeout, eInternal;
66
+ extern VALUE eSyscall, eTimeout, eInternal;
67
67
 
68
68
  // Helper for syscall verbose debugging
69
69
  void
@@ -90,9 +90,10 @@ module Semian
90
90
  InternalError = Class.new(BaseError)
91
91
  OpenCircuitError = Class.new(BaseError)
92
92
 
93
- attr_accessor :maximum_lru_size, :minimum_lru_time
93
+ attr_accessor :maximum_lru_size, :minimum_lru_time, :default_permissions, :namespace
94
94
  self.maximum_lru_size = 500
95
95
  self.minimum_lru_time = 300
96
+ self.default_permissions = 0660
96
97
 
97
98
  def issue_disabled_semaphores_warning
98
99
  return if defined?(@warning_issued)
@@ -138,7 +139,7 @@ module Semian
138
139
  # Mutually exclusive with the 'ticket' argument.
139
140
  # but the resource must have been previously registered otherwise an error will be raised. (bulkhead)
140
141
  #
141
- # +permissions+: Octal permissions of the resource. Default 0660. (bulkhead)
142
+ # +permissions+: Octal permissions of the resource. Default to +Semian.default_permissions+ (0660). (bulkhead)
142
143
  #
143
144
  # +timeout+: Default timeout in seconds. Default 0. (bulkhead)
144
145
  #
@@ -282,7 +283,7 @@ module Semian
282
283
  bulkhead = options.fetch(:bulkhead, true)
283
284
  return unless bulkhead
284
285
 
285
- permissions = options[:permissions] || 0660
286
+ permissions = options[:permissions] || default_permissions
286
287
  timeout = options[:timeout] || 0
287
288
  Resource.new(name, tickets: options[:tickets], quota: options[:quota], permissions: permissions, timeout: timeout)
288
289
  end
@@ -25,7 +25,6 @@ module Semian
25
25
  /MySQL server has gone away/i,
26
26
  /Too many connections/i,
27
27
  /closed MySQL connection/i,
28
- /MySQL client is not connected/i,
29
28
  /Timeout waiting for a response/i,
30
29
  )
31
30
 
@@ -37,9 +36,9 @@ module Semian
37
36
  DEFAULT_PORT = 3306
38
37
 
39
38
  QUERY_WHITELIST = Regexp.union(
40
- /\A\s*ROLLBACK/i,
41
- /\A\s*COMMIT/i,
42
- /\A\s*RELEASE\s+SAVEPOINT/i,
39
+ /\A(?:\/\*.*?\*\/)?\s*ROLLBACK/i,
40
+ /\A(?:\/\*.*?\*\/)?\s*COMMIT/i,
41
+ /\A(?:\/\*.*?\*\/)?\s*RELEASE\s+SAVEPOINT/i,
43
42
  )
44
43
 
45
44
  # The naked methods are exposed as `raw_query` and `raw_connect` for instrumentation purpose
@@ -9,9 +9,15 @@ module Semian
9
9
  end
10
10
  end
11
11
 
12
- def initialize(name, tickets: nil, quota: nil, permissions: 0660, timeout: 0)
12
+ def initialize(name, tickets: nil, quota: nil, permissions: Semian.default_permissions, timeout: 0)
13
+ unless name.is_a?(String) || name.is_a?(Symbol)
14
+ raise TypeError, "name must be a string or symbol, got: #{name.class}"
15
+ end
16
+
13
17
  if Semian.semaphores_enabled?
14
- initialize_semaphore(name, tickets, quota, permissions, timeout) if respond_to?(:initialize_semaphore)
18
+ if respond_to?(:initialize_semaphore)
19
+ initialize_semaphore("#{Semian.namespace}#{name}", tickets, quota, permissions, timeout)
20
+ end
15
21
  else
16
22
  Semian.issue_disabled_semaphores_warning
17
23
  end
@@ -1,3 +1,3 @@
1
1
  module Semian
2
- VERSION = '0.10.4'
2
+ VERSION = '0.11.2'
3
3
  end
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.10.4
4
+ version: 0.11.2
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: 2020-05-25 00:00:00.000000000 Z
13
+ date: 2021-01-27 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake-compiler