basicjrpc 0.1.75 → 0.1.76
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/basicjrpc.gemspec +2 -2
- data/lib/basicjrpc/client.rb +6 -26
- data/lib/basicjrpc/server.rb +5 -7
- data/lib/basicjrpc/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d6b795ccc42f1a96ac34b0346d79d9c8ae0f23da
|
4
|
+
data.tar.gz: 513f4071568d8ae68233cba2c9a4220c0fb91efa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bf5abf3de01fb0f7ab55a04c5278d4a6a1697bf9eb17817b482ffa2d7be820d58747d3f99684c4e83c81a311e432efda36d63479d955e4f77b1cf085ad004945
|
7
|
+
data.tar.gz: d903f08dd46e9c797a1535dc535d3ac2e0e74d1d9019c1e44909689eec7fd62e6977b50bd83468dc65bfb184590689bbff3c66712b2602afe7b0366db4732d46
|
data/basicjrpc.gemspec
CHANGED
@@ -19,9 +19,9 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
|
-
spec.add_development_dependency "bundler", "~> 1.
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.17"
|
23
23
|
spec.add_development_dependency "rake", "~> 10.0"
|
24
24
|
spec.add_runtime_dependency 'redis'
|
25
25
|
spec.add_runtime_dependency 'oj'
|
26
26
|
spec.add_runtime_dependency 'require_all'
|
27
|
-
end
|
27
|
+
end
|
data/lib/basicjrpc/client.rb
CHANGED
@@ -1,22 +1,16 @@
|
|
1
|
-
require 'timeout'
|
2
|
-
|
3
|
-
|
4
|
-
##### WARNING
|
5
|
-
##### WARNING
|
6
|
-
##### THERE IS NO DEAD-CLIENT PROTECTION
|
7
|
-
##### THIS WILL DAMAGE UPSTREAM REQUESTS UNTIL RELOADED
|
8
|
-
|
9
1
|
module BasicJRPC
|
10
2
|
|
11
|
-
# Responding Client
|
12
3
|
class Client
|
13
4
|
def initialize(queue, timeout=10, host="redis")
|
14
5
|
@queue = queue
|
15
6
|
@payload = {}
|
16
7
|
@timeout = timeout
|
17
8
|
@instance_id = SecureRandom.uuid
|
18
|
-
|
19
|
-
|
9
|
+
if host.is_a?(Array)
|
10
|
+
@redis = Redis.new(cluster: host.map { |n| "redis://#{n}:6381" }, driver: :hiredis)
|
11
|
+
elsif host.is_a?(String)
|
12
|
+
@redis = Redis.new(host: @host, port: 6381)
|
13
|
+
end
|
20
14
|
end
|
21
15
|
|
22
16
|
def method_missing(m, *args, &block)
|
@@ -27,23 +21,12 @@ module BasicJRPC
|
|
27
21
|
payload['message_id'] = SecureRandom.uuid
|
28
22
|
payload['instance_id'] = @instance_id
|
29
23
|
payload['response'] = true
|
30
|
-
|
31
24
|
my_message = false
|
32
25
|
|
33
26
|
@redis.rpush(@queue, Oj.dump(payload))
|
34
|
-
|
35
|
-
Timeout::timeout(@timeout) {
|
36
|
-
Oj.load(@redis.blpop(payload['message_id'])[1], :symbol_keys => true)
|
37
|
-
}
|
38
|
-
rescue Exception => e
|
39
|
-
#terminate
|
40
|
-
raise e
|
27
|
+
Oj.load(@redis.blpop(payload['message_id'], timeout: @timeout)[1], :symbol_keys => true)
|
41
28
|
end
|
42
29
|
|
43
|
-
# This must be called
|
44
|
-
def terminate
|
45
|
-
#@nsq_producer.terminate
|
46
|
-
end
|
47
30
|
end
|
48
31
|
|
49
32
|
# Fire And Forget Client
|
@@ -53,9 +36,6 @@ module BasicJRPC
|
|
53
36
|
payload['response'] = true
|
54
37
|
payload['caller'] = caller.first(10)
|
55
38
|
@redis.rpush(@queue, Oj.dump(payload))
|
56
|
-
rescue Exception => e
|
57
|
-
#terminate
|
58
|
-
raise e
|
59
39
|
end
|
60
40
|
end
|
61
41
|
end
|
data/lib/basicjrpc/server.rb
CHANGED
@@ -2,20 +2,22 @@ module BasicJRPC
|
|
2
2
|
class Server
|
3
3
|
|
4
4
|
def initialize queue, injected_class, host="redis"
|
5
|
+
if host.is_a?(Array)
|
6
|
+
@redis = Redis.new(cluster: host.map { |n| "redis://#{n}:6381" }, driver: :hiredis)
|
7
|
+
elsif host.is_a?(String)
|
8
|
+
@redis = Redis.new(host: @host, port: 6381)
|
9
|
+
end
|
5
10
|
@injected_class = injected_class
|
6
11
|
@queue = queue
|
7
|
-
#@nsq_consumer = Nsq::Consumer.new(nsqlookupd: 'dockerlb:4161', topic: @queue, channel: 'server')
|
8
12
|
@host = host
|
9
13
|
end
|
10
14
|
|
11
15
|
def listen(trigger=nil, error_handler=nil)
|
12
16
|
puts "Listening..."
|
13
|
-
@redis = Redis.new(host: @host, port: 6381)
|
14
17
|
|
15
18
|
while true
|
16
19
|
begin
|
17
20
|
redis_response = @redis.blpop(@queue)
|
18
|
-
#@redis.rpush("#{@queue}-processing", redis_response)
|
19
21
|
rescue Redis::TimeoutError
|
20
22
|
puts "ERROR: Redis Read timed out. Retrying"
|
21
23
|
retry
|
@@ -45,9 +47,5 @@ module BasicJRPC
|
|
45
47
|
raise e
|
46
48
|
end
|
47
49
|
|
48
|
-
def terminate
|
49
|
-
#@nsq_consumer.terminate
|
50
|
-
end
|
51
|
-
|
52
50
|
end
|
53
51
|
end
|
data/lib/basicjrpc/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: basicjrpc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.76
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Simpson
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-02-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1.
|
19
|
+
version: '1.17'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '1.
|
26
|
+
version: '1.17'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -120,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
120
120
|
version: '0'
|
121
121
|
requirements: []
|
122
122
|
rubyforge_project:
|
123
|
-
rubygems_version: 2.
|
123
|
+
rubygems_version: 2.6.12
|
124
124
|
signing_key:
|
125
125
|
specification_version: 4
|
126
126
|
summary: Basic JRPC Handler
|