arbiter 1.0.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 51d32f401384d4cb0358b850dfb025cd3843e999
4
+ data.tar.gz: 1d33932533ba1b48d5348918cabec42d329e12e8
5
+ SHA512:
6
+ metadata.gz: 84b5c25c1fb9371f3a76417e07c7aa9729750ca0271238567b79789eae7336af51e3c519ee9cd1e28b511b2c5e41309e3d3571927ea7ab12e658a9af7bfa5e35
7
+ data.tar.gz: 6af9f764ac359470ec5aa26df3da74cad6e4c1002bc02afd5769c4e74c3cf57509597ae23c009c43ee729b7be342c0e1a1e65590fc7816726837578b08ffb8e6
@@ -0,0 +1,44 @@
1
+ require 'ffi-rzmq'
2
+
3
+ module Zeromq
4
+ module Majordomo
5
+ class AsynchronousArbiter
6
+ INFINITE = -1
7
+
8
+ def initialize(address, context, timeout_in_sec, md_service)
9
+ @address = address
10
+ @context = context
11
+ @timeout = timeout_in_sec.to_i * 1000 #ms
12
+ @md_service = md_service
13
+ end
14
+
15
+ def publish(method, params)
16
+ sock = connect
17
+ assert_zmq_ok(sock.send_strings(
18
+ ['', 'MDPC01', @md_service, method.to_s, Marshal.dump(params)]
19
+ ))
20
+ ensure
21
+ disconnect(sock) if sock
22
+ end
23
+
24
+ private
25
+
26
+ def connect
27
+ sock = @context.socket(ZMQ::DEALER)
28
+ assert_zmq_ok(sock.setsockopt(ZMQ::LINGER, INFINITE))
29
+ assert_zmq_ok(sock.setsockopt(ZMQ::SNDTIMEO, @timeout))
30
+ assert_zmq_ok(sock.connect(@address))
31
+ sock
32
+ end
33
+
34
+ def disconnect(sock)
35
+ assert_zmq_ok(sock.disconnect(@address))
36
+ assert_zmq_ok(sock.close)
37
+ end
38
+
39
+ def assert_zmq_ok(rc)
40
+ raise ZMQ::Util.error_string unless ZMQ::Util.resultcode_ok?(rc)
41
+ end
42
+ end
43
+ end
44
+ end
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arbiter
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
5
- prerelease:
4
+ version: 2.0.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Sitter City
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-08-27 00:00:00.000000000 Z
11
+ date: 2015-12-17 00:00:00.000000000 Z
13
12
  dependencies: []
14
13
  description:
15
14
  email:
@@ -21,31 +20,30 @@ files:
21
20
  - lib/arbiter.rb
22
21
  - lib/eventer.rb
23
22
  - lib/resque_arbiter.rb
23
+ - lib/zeromq/majordomo/asynchronous_arbiter.rb
24
24
  - lib/zeromq/proxy.rb
25
- - lib/zeromq_arbiter.rb
26
25
  homepage: https://github.com/sittercity/arbiter
27
26
  licenses: []
27
+ metadata: {}
28
28
  post_install_message:
29
29
  rdoc_options: []
30
30
  require_paths:
31
31
  - lib
32
32
  - spec
33
33
  required_ruby_version: !ruby/object:Gem::Requirement
34
- none: false
35
34
  requirements:
36
- - - ! '>='
35
+ - - ">="
37
36
  - !ruby/object:Gem::Version
38
37
  version: '0'
39
38
  required_rubygems_version: !ruby/object:Gem::Requirement
40
- none: false
41
39
  requirements:
42
- - - ! '>='
40
+ - - ">="
43
41
  - !ruby/object:Gem::Version
44
42
  version: '0'
45
43
  requirements: []
46
44
  rubyforge_project:
47
- rubygems_version: 1.8.24
45
+ rubygems_version: 2.4.5
48
46
  signing_key:
49
- specification_version: 3
47
+ specification_version: 4
50
48
  summary: A simple eventing framework
51
49
  test_files: []
@@ -1,99 +0,0 @@
1
- require 'arbiter'
2
- require 'ffi-rzmq'
3
- require 'multi_json'
4
-
5
- class ZeromqArbiter < Arbiter
6
-
7
- class << self
8
- attr_accessor :frontend, :logger
9
- end
10
-
11
- def self.publish(message, metadata)
12
- context = ZMQ::Context.new
13
-
14
- outbound = context.socket(ZMQ::PUSH)
15
- outbound.connect(frontend)
16
-
17
- outbound.send_string(
18
- MultiJson.dump(
19
- :message => message,
20
- :metadata => metadata
21
- )
22
- )
23
-
24
- outbound.close
25
- context.terminate
26
- end
27
-
28
- def listen(proxy)
29
- raise 'Must provide proxy location!' unless proxy
30
-
31
- ctx = ZMQ::Context.new
32
- socket = ctx.socket(ZMQ::PULL)
33
- rc = socket.connect(proxy)
34
-
35
- raise "Could not connect to #{proxy}!" unless rc == 0
36
-
37
- log :info, "Connected to #{proxy}"
38
-
39
- while true
40
- msg = ''
41
- rc = socket.recv_string(msg)
42
-
43
- if error_check(rc)
44
- break
45
- else
46
- process_message(msg)
47
- end
48
- end
49
-
50
- socket.close
51
- ctx.terminate
52
- end
53
-
54
- protected
55
-
56
- def log(type, msg)
57
- if self.class.logger
58
- self.class.logger.send(type, msg)
59
- end
60
- end
61
-
62
- def process_message(message)
63
- message = MultiJson.decode(message)
64
- log :info, "Processing: #{message}"
65
-
66
- begin
67
- self.class.perform(message['message'].to_sym, symbolize_nested_keys(message['metadata']))
68
- rescue Exception => e
69
- log :error, e
70
- end
71
- end
72
-
73
- def error_check(rc)
74
- if ZMQ::Util.resultcode_ok?(rc)
75
- false
76
- else
77
- log :error, "Operation failed, errno [#{ZMQ::Util.errno}] description [#{ZMQ::Util.error_string}]"
78
- caller(1).each { |callstack| log :error, callstack }
79
- true
80
- end
81
- end
82
-
83
- def symbolize_nested_keys(data)
84
- case data
85
- when Hash
86
- data.map {|k, v|
87
- {k.to_sym => symbolize_nested_keys(v)}
88
- }.inject({}) { |coll, symbol_key_hash|
89
- coll.merge(symbol_key_hash)
90
- }
91
- when Array
92
- data.collect { |a|
93
- symbolize_nested_keys(a)
94
- }
95
- else
96
- data
97
- end
98
- end
99
- end