semian 0.9.1 → 0.10.4

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: aefbea0e823c25d564efb6ab2859f90bd27125b815f097ad1a7aa9e7109e58ba
4
- data.tar.gz: d9c389c8954f6c332018ec36cece20d6847d63a781fec755354151023d5d3646
3
+ metadata.gz: e66732f3eff2bf185bafb6e8415d04bb49a946a9da90e497063c325c76361997
4
+ data.tar.gz: 05bd964a1d2760b4e9d7274732f3bf31d7e788f8cffb198a5c1715ace826a85d
5
5
  SHA512:
6
- metadata.gz: aa9ea2602e2b9671d83273904bc7d813e5c39a15a3c5938dc03460129b67e7257719a95a6ad4614bdd6255e416f1ef2c7b046a0a3b94a9185cb6b5ab093b2dd1
7
- data.tar.gz: 584f1e7243fa3a28f7de7d59a4b2655616a41800b8e366138aedb20bedfcc9264e18e7a339c95147e062fa7cb18ff27b2edb529c11dcd1ec28c1295fadde5c7d
6
+ metadata.gz: 2a94a193f5c90761c3a07bee03f8a28bcff5ad76fb36dcaba07499982fccbf5170f4fd552b9b56fc4e6ae73295f36134c4fbf87db627ebd75df72cd53f8ee77b
7
+ data.tar.gz: ad6d78abed72e04575bf33e50e795e940112c2ee97bf573cec706c7111b59afe682cc549e8dbb2dbd8b3a5de8a1efa8eb1bfb3b6aa57f9f72b269153c77bf311
@@ -287,7 +287,7 @@ module Semian
287
287
  Resource.new(name, tickets: options[:tickets], quota: options[:quota], permissions: permissions, timeout: timeout)
288
288
  end
289
289
 
290
- def require_keys!(required = [], **options)
290
+ def require_keys!(required, options)
291
291
  diff = required - options.keys
292
292
  unless diff.empty?
293
293
  raise ArgumentError, "Missing required arguments for Semian: #{diff}"
@@ -79,22 +79,22 @@ module Semian
79
79
  raw_semian_options.nil?
80
80
  end
81
81
 
82
- def request_response(*)
82
+ def request_response(*, **)
83
83
  return super if disabled?
84
84
  acquire_semian_resource(adapter: :grpc, scope: :request_response) { super }
85
85
  end
86
86
 
87
- def client_streamer(*)
87
+ def client_streamer(*, **)
88
88
  return super if disabled?
89
89
  acquire_semian_resource(adapter: :grpc, scope: :client_streamer) { super }
90
90
  end
91
91
 
92
- def server_streamer(*)
92
+ def server_streamer(*, **)
93
93
  return super if disabled?
94
94
  acquire_semian_resource(adapter: :grpc, scope: :server_streamer) { super }
95
95
  end
96
96
 
97
- def bidi_streamer(*)
97
+ def bidi_streamer(*, **)
98
98
  return super if disabled?
99
99
  acquire_semian_resource(adapter: :grpc, scope: :bidi_streamer) { super }
100
100
  end
@@ -5,10 +5,6 @@ class LRUHash
5
5
  # everytime we set a new resource. A default window of
6
6
  # 5 minutes will allow empty item to stay in the hash
7
7
  # for a maximum of 5 minutes
8
- extend Forwardable
9
- def_delegators :@table, :size, :count, :empty?, :values
10
- attr_reader :table
11
-
12
8
  class NoopMutex
13
9
  def synchronize(*)
14
10
  yield
@@ -65,6 +61,22 @@ class LRUHash
65
61
  end
66
62
  end
67
63
 
64
+ def size
65
+ @lock.synchronize { @table.size }
66
+ end
67
+
68
+ def count(&block)
69
+ @lock.synchronize { @table.count(&block) }
70
+ end
71
+
72
+ def empty?
73
+ @lock.synchronize { @table.empty? }
74
+ end
75
+
76
+ def values
77
+ @lock.synchronize { @table.values }
78
+ end
79
+
68
80
  def set(key, resource)
69
81
  @lock.synchronize do
70
82
  @table.delete(key)
@@ -116,7 +116,7 @@ module Semian
116
116
  acquire_semian_resource(adapter: :mysql, scope: :connection) { raw_connect(*args) }
117
117
  end
118
118
 
119
- def acquire_semian_resource(*)
119
+ def acquire_semian_resource(**)
120
120
  super
121
121
  rescue ::Mysql2::Error => error
122
122
  if error.is_a?(PingFailure) || (!error.is_a?(::Mysql2::SemianError) && error.message.match?(CONNECTION_ERROR))
@@ -91,6 +91,28 @@ module Semian
91
91
  end
92
92
  end
93
93
 
94
+ def with_resource_timeout(temp_timeout)
95
+ timeout = options[:timeout]
96
+ connect_timeout = options[:connect_timeout]
97
+ read_timeout = options[:read_timeout]
98
+ write_timeout = options[:write_timeout]
99
+
100
+ begin
101
+ connection.timeout = temp_timeout if connected?
102
+ options[:timeout] = Float(temp_timeout),
103
+ options[:connect_timeout] = Float(temp_timeout)
104
+ options[:read_timeout] = Float(temp_timeout)
105
+ options[:write_timeout] = Float(temp_timeout)
106
+ yield
107
+ ensure
108
+ options[:timeout] = timeout
109
+ options[:connect_timeout] = connect_timeout
110
+ options[:read_timeout] = read_timeout
111
+ options[:write_timeout] = write_timeout
112
+ connection.timeout = self.timeout if connected?
113
+ end
114
+ end
115
+
94
116
  private
95
117
 
96
118
  def resource_exceptions
@@ -4,8 +4,8 @@ module Semian
4
4
 
5
5
  class << Semian::Resource
6
6
  # Ensure that there can only be one resource of a given type
7
- def instance(*args)
8
- Semian.resources[args.first] ||= ProtectedResource.new(args.first, new(*args), nil)
7
+ def instance(name, **kwargs)
8
+ Semian.resources[name] ||= ProtectedResource.new(name, new(name, **kwargs), nil)
9
9
  end
10
10
  end
11
11
 
@@ -44,7 +44,7 @@ module Semian
44
44
 
45
45
  module ThreadSafe
46
46
  class SlidingWindow < Simple::SlidingWindow
47
- def initialize(*)
47
+ def initialize(**)
48
48
  super
49
49
  @lock = Mutex.new
50
50
  end
@@ -1,3 +1,3 @@
1
1
  module Semian
2
- VERSION = '0.9.1'
2
+ VERSION = '0.10.4'
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.9.1
4
+ version: 0.10.4
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: 2019-11-14 00:00:00.000000000 Z
13
+ date: 2020-05-25 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake-compiler
@@ -234,7 +234,8 @@ files:
234
234
  homepage: https://github.com/shopify/semian
235
235
  licenses:
236
236
  - MIT
237
- metadata: {}
237
+ metadata:
238
+ allowed_push_host: https://rubygems.org
238
239
  post_install_message:
239
240
  rdoc_options: []
240
241
  require_paths: