pigato 0.4.2 → 0.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/examples/echo_worker.rb +2 -0
- data/lib/pigato/base.rb +7 -2
- data/lib/pigato/client.rb +8 -4
- data/lib/pigato/version.rb +1 -1
- data/lib/pigato/worker.rb +64 -48
- metadata +14 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bdf1137eca61937e2e82029877d8019e644e666d
|
4
|
+
data.tar.gz: fa72b975774ccbbb195da86b0fceae53a302a473
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bd2a025e0dcc5242622fac54e0e8e60ec32fdf7efbac0388feb68ece36cd93e9c778f07cb4b927a050f949028c973bd42a97f3454abf27c62ea701a818d4da2b
|
7
|
+
data.tar.gz: 38cef7013fabeaea9c6dd52af0e875e9928d8891d3d74d1a03b8c64b6f3f7f664b699dc803bda91ce5e33d8ff7b2055d8948564429348025f83de1de721f36b2
|
data/examples/echo_worker.rb
CHANGED
data/lib/pigato/base.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
class Pigato::Base
|
2
2
|
|
3
3
|
@@sockets = {}
|
4
|
+
@@sockets_ids = {}
|
4
5
|
@@mtxs = {}
|
5
6
|
@@mtx = Mutex.new
|
7
|
+
@@global_heartbeat_at = Time.now
|
6
8
|
|
7
9
|
def init
|
8
10
|
@iid = SecureRandom.uuid
|
@@ -49,14 +51,16 @@ class Pigato::Base
|
|
49
51
|
end
|
50
52
|
|
51
53
|
socket = ctx.socket ZMQ::DEALER
|
52
|
-
|
54
|
+
sid = SecureRandom.uuid
|
55
|
+
socket.identity = sid
|
53
56
|
socket.connect @broker
|
54
57
|
|
55
58
|
if !@conf[:timeout].nil? then
|
56
|
-
socket.rcvtimeo = @conf[:timeout]
|
59
|
+
socket.rcvtimeo = @conf[:timeout]
|
57
60
|
end
|
58
61
|
|
59
62
|
@@sockets[get_iid] = socket
|
63
|
+
@@sockets_ids[get_iid] = sid
|
60
64
|
}
|
61
65
|
end
|
62
66
|
|
@@ -73,6 +77,7 @@ class Pigato::Base
|
|
73
77
|
rescue
|
74
78
|
end
|
75
79
|
@@sockets.delete(iid)
|
80
|
+
@@sockets_ids.delete(iid)
|
76
81
|
end
|
77
82
|
}
|
78
83
|
end
|
data/lib/pigato/client.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require "#{File.dirname(__FILE__)}/base.rb"
|
2
2
|
|
3
3
|
class Pigato::Client < Pigato::Base
|
4
|
-
|
5
4
|
@@mtx = Mutex.new
|
6
5
|
@@ctxs = {}
|
7
6
|
@@sockets = {}
|
@@ -23,20 +22,25 @@ class Pigato::Client < Pigato::Base
|
|
23
22
|
end
|
24
23
|
end
|
25
24
|
|
26
|
-
def
|
25
|
+
def send msg
|
27
26
|
iid = get_iid
|
28
27
|
start if @@sockets[iid] == nil && @conf[:autostart]
|
29
|
-
|
30
28
|
socket = get_socket
|
31
29
|
return nil if socket.nil?
|
30
|
+
socket.send_message msg
|
31
|
+
true
|
32
|
+
end
|
32
33
|
|
34
|
+
def request service, request, opts = {}
|
33
35
|
request = [Oj.dump(request), Oj.dump(opts)]
|
34
36
|
|
35
37
|
rid = SecureRandom.uuid
|
36
38
|
request = [Pigato::C_CLIENT, Pigato::W_REQUEST, service, rid].concat(request)
|
37
39
|
msg = ZMQ::Message.new
|
38
40
|
request.reverse.each{|p| msg.push(ZMQ::Frame(p))}
|
39
|
-
|
41
|
+
|
42
|
+
res = send msg
|
43
|
+
return nil if res.nil?
|
40
44
|
|
41
45
|
res = []
|
42
46
|
while 1 do
|
data/lib/pigato/version.rb
CHANGED
data/lib/pigato/worker.rb
CHANGED
@@ -22,80 +22,96 @@ class Pigato::Worker < Pigato::Base
|
|
22
22
|
@reply_to = nil
|
23
23
|
@reply_rid = nil
|
24
24
|
@reply_service = nil
|
25
|
-
|
25
|
+
|
26
26
|
init
|
27
27
|
|
28
28
|
if @conf[:autostart]
|
29
29
|
start
|
30
30
|
end
|
31
|
+
|
32
|
+
Thread.new do
|
33
|
+
client = Pigato::Client.new(broker, { :autostart => true })
|
34
|
+
loop do
|
35
|
+
@@mtx.lock
|
36
|
+
begin
|
37
|
+
if Time.now > @@global_heartbeat_at
|
38
|
+
@@sockets_ids.each do |iid, sid|
|
39
|
+
request = [Pigato::C_CLIENT, Pigato::W_HEARTBEAT, "worker", sid]
|
40
|
+
msg = ZMQ::Message.new
|
41
|
+
request.reverse.each{|p| msg.push(ZMQ::Frame(p))}
|
42
|
+
client.send msg
|
43
|
+
end
|
44
|
+
@@global_heartbeat_at = Time.now + 2
|
45
|
+
end
|
46
|
+
rescue => e
|
47
|
+
puts e
|
48
|
+
end
|
49
|
+
@@mtx.unlock
|
50
|
+
sleep 2
|
51
|
+
end
|
52
|
+
end
|
31
53
|
end
|
32
54
|
|
33
55
|
def reply reply
|
34
56
|
reply = [@reply_to, '', @reply_rid, '0'].concat([Oj.dump(reply)])
|
35
57
|
send Pigato::W_REPLY, reply
|
36
58
|
end
|
37
|
-
|
59
|
+
|
38
60
|
def recv
|
61
|
+
val = nil
|
39
62
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
@reply_service = nil
|
63
|
+
@reply_rid = nil
|
64
|
+
@reply_to = nil
|
65
|
+
@reply_service = nil
|
44
66
|
|
45
|
-
|
46
|
-
|
47
|
-
start if @@sockets[iid] == nil && @conf[:autostart]
|
67
|
+
iid = get_iid
|
48
68
|
|
49
|
-
|
50
|
-
return nil if socket.nil?
|
69
|
+
start if @@sockets[iid] == nil && @conf[:autostart]
|
51
70
|
|
52
|
-
|
71
|
+
socket = get_socket
|
72
|
+
return nil if socket.nil?
|
53
73
|
|
54
|
-
|
74
|
+
socket.rcvtimeo = @conf[:timeout]
|
55
75
|
|
56
|
-
|
76
|
+
msg = socket.recv_message
|
57
77
|
|
58
|
-
|
59
|
-
|
78
|
+
if msg && msg.size
|
79
|
+
@liveness = HEARTBEAT_LIVENESS
|
60
80
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
81
|
+
header = msg.pop.data
|
82
|
+
if header != Pigato::W_WORKER
|
83
|
+
puts "E: Header is not Pigato::WORKER"
|
84
|
+
return nil
|
85
|
+
end
|
66
86
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
when Pigato::W_HEARTBEAT
|
80
|
-
# do nothing
|
81
|
-
when Pigato::W_DISCONNECT
|
82
|
-
start
|
83
|
-
else
|
84
|
-
end
|
87
|
+
command = msg.pop.data
|
88
|
+
|
89
|
+
case command
|
90
|
+
when Pigato::W_REQUEST
|
91
|
+
@reply_to = msg.pop.data
|
92
|
+
@reply_service = msg.pop.data
|
93
|
+
msg.pop # empty
|
94
|
+
@reply_rid = msg.pop.data
|
95
|
+
val = Oj.load(msg.pop.data)
|
96
|
+
when Pigato::W_HEARTBEAT
|
97
|
+
when Pigato::W_DISCONNECT
|
98
|
+
start
|
85
99
|
else
|
86
|
-
@liveness -= 1
|
87
|
-
if @liveness == 0
|
88
|
-
sleep 0.001 * @conf[:reconnect]
|
89
|
-
start
|
90
|
-
end
|
91
100
|
end
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
101
|
+
else
|
102
|
+
@liveness -= 1
|
103
|
+
if @liveness == 0
|
104
|
+
sleep 0.001 * @conf[:reconnect]
|
105
|
+
start
|
96
106
|
end
|
107
|
+
end
|
97
108
|
|
109
|
+
if Time.now > @heartbeat_at
|
110
|
+
send Pigato::W_HEARTBEAT
|
111
|
+
@heartbeat_at = Time.now + 0.001 * @conf[:heartbeat]
|
98
112
|
end
|
113
|
+
|
114
|
+
val
|
99
115
|
end
|
100
116
|
|
101
117
|
def start
|
metadata
CHANGED
@@ -1,69 +1,69 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pigato
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paolo Ardoino
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-02-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.8'
|
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
26
|
version: '1.8'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ~>
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '10.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rbczmq
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ~>
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: 1.7.9
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ~>
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 1.7.9
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: oj
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: 2.14.1
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ~>
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: 2.14.1
|
69
69
|
description: PIGATO-RUBY
|
@@ -73,7 +73,7 @@ executables: []
|
|
73
73
|
extensions: []
|
74
74
|
extra_rdoc_files: []
|
75
75
|
files:
|
76
|
-
-
|
76
|
+
- .gitignore
|
77
77
|
- CODE_OF_CONDUCT.md
|
78
78
|
- Gemfile
|
79
79
|
- LICENSE.txt
|
@@ -101,19 +101,18 @@ require_paths:
|
|
101
101
|
- lib
|
102
102
|
required_ruby_version: !ruby/object:Gem::Requirement
|
103
103
|
requirements:
|
104
|
-
- -
|
104
|
+
- - '>='
|
105
105
|
- !ruby/object:Gem::Version
|
106
106
|
version: '0'
|
107
107
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
108
|
requirements:
|
109
|
-
- -
|
109
|
+
- - '>='
|
110
110
|
- !ruby/object:Gem::Version
|
111
111
|
version: '0'
|
112
112
|
requirements: []
|
113
113
|
rubyforge_project:
|
114
|
-
rubygems_version: 2.
|
114
|
+
rubygems_version: 2.4.7
|
115
115
|
signing_key:
|
116
116
|
specification_version: 4
|
117
117
|
summary: PIGATO-RUBY
|
118
118
|
test_files: []
|
119
|
-
has_rdoc:
|