semian 0.10.0 → 0.10.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/semian/semian.c +5 -0
- data/ext/semian/sysv_semaphores.h +1 -1
- data/lib/semian.rb +1 -1
- data/lib/semian/grpc.rb +4 -4
- data/lib/semian/lru_hash.rb +16 -4
- data/lib/semian/mysql2.rb +1 -1
- data/lib/semian/resource.rb +2 -2
- data/lib/semian/simple_sliding_window.rb +1 -1
- data/lib/semian/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed326cf0bc3f6b5b1ae9cb18b6170b4d47cef460883aca5c20f2f7d113403dbc
|
4
|
+
data.tar.gz: e229fbdf17441a0ccb89963196fe1f4ff3a41a43e4c0be633b4164842ffbb4ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 167e750d067604930d2097fbcd98095eadcb01a4d614483dd2ed55a7bec861f602e8185d51a9f57f982e35ca66ec2d1d74bd7bed7e2180ae0210a869b0015ffc
|
7
|
+
data.tar.gz: 5c4fa76a0143852aa71a838f3c2b4632f97db54485b05275ae96c5ee526ed4a3bf71bc67d695c39c53386873303fff50afdcfd3fc32af667160be1dd827609d8
|
data/ext/semian/semian.c
CHANGED
@@ -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);
|
data/lib/semian.rb
CHANGED
@@ -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
|
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}"
|
data/lib/semian/grpc.rb
CHANGED
@@ -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
|
data/lib/semian/lru_hash.rb
CHANGED
@@ -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)
|
data/lib/semian/mysql2.rb
CHANGED
@@ -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))
|
data/lib/semian/resource.rb
CHANGED
@@ -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(
|
8
|
-
Semian.resources[
|
7
|
+
def instance(name, **kwargs)
|
8
|
+
Semian.resources[name] ||= ProtectedResource.new(name, new(name, **kwargs), nil)
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
data/lib/semian/version.rb
CHANGED
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
|
+
version: 0.10.5
|
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: 2020-10-14 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:
|