amiral 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/amiral/version.rb +1 -1
  2. data/lib/amiral.rb +14 -45
  3. metadata +2 -2
@@ -1,3 +1,3 @@
1
1
  module Amiral
2
- VERSION = '0.1.4'
2
+ VERSION = '0.1.5'
3
3
  end
data/lib/amiral.rb CHANGED
@@ -254,11 +254,9 @@ module Amiral
254
254
 
255
255
  def initialize settings
256
256
  @settings = {
257
+ :prefix => "amiral:",
257
258
  :redis_in => Redis.new,
258
259
  :redis_out => Redis.new,
259
- :exchange => "req",
260
- :queue_ack => "ack",
261
- :queue_response => "res",
262
260
  :keytype => :dss,
263
261
  :hostname => hostname,
264
262
  :loglevel => Logger::INFO,
@@ -291,8 +289,8 @@ module Amiral
291
289
  end
292
290
 
293
291
  def listen
294
- exchange = @settings[:exchange]
295
- @redis_in.subscribe exchange do |on|
292
+ prefix = @settings[:prefix]
293
+ @redis_in.subscribe "#{prefix}req" do |on|
296
294
 
297
295
  on.message do |x, payload|
298
296
 
@@ -334,16 +332,19 @@ module Amiral
334
332
  end
335
333
 
336
334
  def send_ack response
337
- send_payload @settings[:queue_ack], response
335
+ send_payload "ack", response
338
336
  end
339
337
 
340
338
  def send_response response
341
- send_payload @settings[:queue_response], response
339
+ send_payload "res", response
342
340
  end
343
341
 
344
- def send_payload q, response
342
+ def send_payload type, response
343
+ puts "response: #{response}"
344
+ uuid = response[:in_reply_to]
345
345
  response[:hostname] = @settings[:hostname]
346
- @redis_out.lpush q, serialize(response)
346
+ prefix = @settings[:prefix]
347
+ @redis_out.publish "#{prefix}#{type}:#{uuid}", serialize(response)
347
348
  end
348
349
  end
349
350
 
@@ -353,9 +354,7 @@ module Amiral
353
354
  def initialize settings
354
355
  @settings = {
355
356
  :redis => Redis.new,
356
- :exchange => "req",
357
- :queue_ack => "ack",
358
- :queue_response => "res",
357
+ :prefix => "amiral:",
359
358
  :ack_timeout => 2,
360
359
  :response_timeout => 5,
361
360
  :match_spec => {:all => true},
@@ -391,43 +390,13 @@ module Amiral
391
390
  @redis.publish @settings[:exchange], serialize(request)
392
391
 
393
392
  # pop items for 2 seconds
394
- acks = []
393
+ acks = {}
394
+ resps = {}
395
395
  puts "accepting acknowledgements for #{@settings[:ack_timeout]} seconds"
396
396
  limit = timestamp + @settings[:ack_timeout]
397
397
 
398
- while timestamp < limit do
399
- t = timestamp
400
- t = (limit - t == 0) ? 1 : (limit - t)
401
- (q, data) = @redis.brpop(@settings[:queue_ack], t)
402
- if data
403
- ack = deserialize data
404
- acks << ack if ack['in_reply_to'] == uuid
405
- end
406
- end
407
-
408
- pos_acks = acks.keep_if do |a|
409
- a['status'] == 'start'
410
- end
411
-
412
- remaining = pos_acks.length
413
- puts "got #{remaining}/#{acks.length} positive acknowledgements"
414
-
415
- # wait for responses now
398
+ ## XXX: broken for now
416
399
  @responses = []
417
- limit = timestamp + @settings[:response_timeout]
418
- while timestamp < limit && remaining > 0 do
419
- t = timestamp
420
- t = (limit - t == 0) ? 1 : (limit - t)
421
- (q, data) = @redis.brpop(@settings[:queue_response], t)
422
-
423
- if data
424
- res = deserialize data
425
- if res['in_reply_to'] == uuid
426
- @responses << res
427
- remaining -= 1
428
- end
429
- end
430
- end
431
400
 
432
401
  puts "got #{@responses.length}/#{pos_acks.length} responses"
433
402
  @responses
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: amiral
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-13 00:00:00.000000000 Z
12
+ date: 2012-11-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: redis