beetle_joevandyk_extensions 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,16 +1,23 @@
1
1
  require "beetle_joevandyk_extensions/version"
2
2
  require 'beetle'
3
+ require 'timeout'
3
4
 
4
5
  module BeetleJoevandykExtensions
6
+ class BeetleError < RuntimeError; end
7
+
8
+ DEFAULT_TIMEOUT = 10
9
+
5
10
  def rpc name, message, options={}
6
11
  client = Beetle::Client.new
7
12
  client.register_message name
8
- status, result = client.rpc(name, message.to_json)
9
- raise result.to_s if status != "OK"
10
- JSON.parse(result)
13
+ Timeout.timeout(options[:timeout] || DEFAULT_TIMEOUT, BeetleError) do
14
+ status, result = client.rpc(name, message.to_json)
15
+ raise BeetleError.new(result.to_s) if status != "OK"
16
+ JSON.parse(result)
17
+ end
11
18
  end
12
19
 
13
- def listener name, &block
20
+ def listen name, &block
14
21
  client = Beetle::Client.new
15
22
  client.register_queue name
16
23
  client.register_handler name do |input|
@@ -20,6 +27,12 @@ module BeetleJoevandykExtensions
20
27
  puts "Started #{ name } at #{ Time.now }"
21
28
  end
22
29
  end
30
+
31
+ def publish name, message
32
+ client = Beetle::Client.new
33
+ client.register_message name
34
+ client.publish name, message
35
+ end
23
36
  end
24
37
 
25
38
  Beetle.extend(BeetleJoevandykExtensions)
@@ -1,3 +1,3 @@
1
1
  module BeetleJoevandykExtensions
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: beetle_joevandyk_extensions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: