nexia_worker_roulette 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cd0eeadb6b1a835e8b4e048efd15e646cd00640a
4
- data.tar.gz: 8485398a8d5d7ef3f7fea43615ace7a685a38958
3
+ metadata.gz: 485a631bf7929866af1715af3649ce0ef5abcd49
4
+ data.tar.gz: 562bdf170332fe368447e8c2dac02ec9a6fbabd8
5
5
  SHA512:
6
- metadata.gz: 764df03a358b164235df1c13ae983c1633aaadf45e485bb9e1d859ea2f13df46f691aee85dadd94c878c429d614140c1d44b077f10cd9f20d11a6f6af4ec0c05
7
- data.tar.gz: bb213af4edb64d491bf89b8df8e4bf337dcffc7371d697b7dcb12ad3eb77bfe7be9923675ee2edfe442df5629c5a61f4046bf2c156d58af7fc6a29bb125d0f37
6
+ metadata.gz: 24ad87c7f75d708465ae59e0844f9157feb850bf8c631da32deb47f3f6d480ae80c7a2848a539acf3d25263602ec9c6126418fb31f58a55eedd11f225f2e4a27
7
+ data.tar.gz: d40ea3cdb9da663ae62d5413a7445b14daf5170f4c42353f77609c569c9351fb4b7e6442074e83a8c64240ef830c4c906f817b2e1bb22186d6713dd13daf0f2a
@@ -3,7 +3,8 @@ module QueueLatencyTracker
3
3
 
4
4
  class Foreman
5
5
  def process(work_order, _channel)
6
- work_order['headers'].merge!("queued_at" => (Time.now.to_f * GRANULARITY).to_i)
6
+ work_order['headers'].merge!(
7
+ "queued_at" => (Time.now.to_f * GRANULARITY).to_i) if work_order.is_a?(Hash) && work_order["headers"]
7
8
  work_order
8
9
  end
9
10
  end
@@ -1,3 +1,3 @@
1
1
  module WorkerRoulette
2
- VERSION = '0.2.1'
2
+ VERSION = '0.2.2'
3
3
  end
@@ -76,7 +76,7 @@ module WorkerRoulette
76
76
  QueueLatencyTracker.configure(
77
77
  {
78
78
  server_name: `hostname`.chomp,
79
- logstash_server_ip: Resolv::DNS.new.getaddress(config[:logstash_server_name]).to_s,
79
+ logstash_server_ip: ip_address(config[:logstash_server_name]),
80
80
  logstash_port: config[:logstash_port]
81
81
  }
82
82
  )
@@ -112,6 +112,10 @@ module WorkerRoulette
112
112
 
113
113
  private
114
114
 
115
+ def ip_address(server_name)
116
+ server_name == "localhost" ? "127.0.0.1" : Resolv::DNS.new.getaddress(server_name).to_s
117
+ end
118
+
115
119
  def new_redis
116
120
  if @evented
117
121
  require 'eventmachine'
@@ -12,7 +12,13 @@ module WorkerRoulette
12
12
  let(:foreman_work_order) { Hash["payload" => "foreman"] }
13
13
  let(:work_orders_with_headers) { default_headers.merge({ "payload" => work_orders }) }
14
14
  let(:jsonized_work_orders_with_headers) { [WorkerRoulette.dump(work_orders_with_headers)] }
15
- let(:worker_roulette) { WorkerRoulette.start(evented: true) }
15
+ let(:latency_tracker) {
16
+ {
17
+ logstash_server_name: "localhost",
18
+ logstash_port: 7777
19
+ }
20
+ }
21
+ let(:worker_roulette) { WorkerRoulette.start(evented: true, latency_tracker: latency_tracker) }
16
22
  let(:redis) { Redis.new(worker_roulette.redis_config) }
17
23
 
18
24
  before do
@@ -59,7 +65,9 @@ module WorkerRoulette
59
65
  extra_headers = {"foo" => "bars"}
60
66
  foreman.enqueue_work_order(work_orders, extra_headers) do
61
67
  work_orders_with_headers["headers"].merge!(extra_headers)
62
- expect(redis.lrange(sender, 0, -1)).to eq([WorkerRoulette.dump(work_orders_with_headers)])
68
+ redis_work_orders = redis.lrange(sender, 0, -1)
69
+ work_orders = redis_work_orders.map {|wo| Oj.load(wo.to_s) }
70
+ expect(work_orders).to eq([work_orders_with_headers])
63
71
  done
64
72
  end
65
73
  end
@@ -1,4 +1,5 @@
1
1
  require "spec_helper"
2
+
2
3
  module WorkerRoulette
3
4
  class Tradesman
4
5
  attr_reader :lua
@@ -6,14 +7,15 @@ module WorkerRoulette
6
7
 
7
8
  describe WorkerRoulette do
8
9
  let(:sender) { 'katie_80' }
10
+ let(:queued_at) { 1234567 }
9
11
  let(:work_orders) { ["hello", "foreman"] }
10
- let(:queued_at) { 1234567 }
11
- let(:default_headers) { Hash["headers" => { "sender" => sender, "queued_at" => (queued_at.to_f * 1_000_000).to_i }] }
12
+ let(:default_headers) { Hash["headers" => { "sender" => sender }] }
12
13
  let(:hello_work_order) { Hash['payload' => "hello"] }
13
14
  let(:foreman_work_order) { Hash['payload' => "foreman"] }
14
15
  let(:work_orders_with_headers) { default_headers.merge({ 'payload' => work_orders }) }
15
16
  let(:jsonized_work_orders_with_headers) { [WorkerRoulette.dump(work_orders_with_headers)] }
16
- let(:worker_roulette) { WorkerRoulette.start }
17
+ let(:worker_roulette) { WorkerRoulette.start(evented: false, latency_tracker: latency_tracker) }
18
+ let(:latency_tracker) { nil }
17
19
 
18
20
  let(:redis) { Redis.new(worker_roulette.redis_config) }
19
21
 
@@ -56,13 +58,17 @@ module WorkerRoulette
56
58
  extra_headers = { 'foo' => 'bars' }
57
59
  foreman.enqueue_work_order(work_orders, extra_headers)
58
60
  work_orders_with_headers['headers'].merge!(extra_headers)
59
- expect(redis.lrange(sender, 0, -1)).to eq([WorkerRoulette.dump(work_orders_with_headers)])
61
+ redis_work_orders = redis.lrange(sender, 0, -1)
62
+ work_orders = redis_work_orders.map {|wo| Oj.load(wo.to_s) }
63
+ expect(work_orders).to eq([work_orders_with_headers])
60
64
  end
61
65
 
62
66
  it "posts the sender's id to the job board with an order number" do
63
67
  foreman.enqueue_work_order(work_orders.first)
64
68
  worker_roulette.foreman('other_forman').enqueue_work_order(work_orders.last)
65
- expect(redis.zrange(foreman.job_board_key, 0, -1, with_scores: true)).to eq([[sender, 1.0], ["other_forman", 2.0]])
69
+ redis_work_orders = redis.zrange(foreman.job_board_key, 0, -1, with_scores: true)
70
+ work_orders = redis_work_orders.map {|wo| Oj.load(wo.to_s) }
71
+ expect(work_orders).to eq([[sender, 1.0], ["other_forman", 2.0]])
66
72
  end
67
73
 
68
74
  it "generates a monotically increasing score for senders not on the job board, but not for senders already there" do
@@ -144,10 +150,21 @@ module WorkerRoulette
144
150
  end
145
151
  end
146
152
 
147
- it "sees queued_at in the header" do
148
- tradesman.wait_for_work_orders do |redis_work_orders|
149
- expect(redis_work_orders.first["headers"]["queued_at"]).to_not be_nil
150
- allow(tradesman).to receive(:wait_for_work_orders)
153
+ context "when latency tracker is enabled" do
154
+ let(:default_headers) { Hash["headers" => { "sender" => sender, "queued_at" => (queued_at.to_f * 1_000_000).to_i }] }
155
+ let(:queued_at) { 1234567 }
156
+ let(:latency_tracker) {
157
+ {
158
+ logstash_server_name: "localhost",
159
+ logstash_port: 7777
160
+ }
161
+ }
162
+
163
+ it "sees queued_at in the header" do
164
+ tradesman.wait_for_work_orders do |redis_work_orders|
165
+ expect(redis_work_orders.first["headers"]["queued_at"]).to_not be_nil
166
+ allow(tradesman).to receive(:wait_for_work_orders)
167
+ end
151
168
  end
152
169
  end
153
170
 
@@ -1,8 +1,14 @@
1
1
  require "spec_helper"
2
2
 
3
3
  module WorkerRoulette
4
- describe "Read Lock" do
5
- let(:worker_roulette) { WorkerRoulette.start(evented: false) }
4
+ describe "Read Lock" do
5
+ let(:latency_tracker) {
6
+ {
7
+ logstash_server_name: "localhost",
8
+ logstash_port: 7777
9
+ }
10
+ }
11
+ let(:worker_roulette) { WorkerRoulette.start(evented: false, latency_tracker: latency_tracker) }
6
12
  let(:redis) { Redis.new(worker_roulette.redis_config) }
7
13
  let(:sender) { "katie_80" }
8
14
  let(:work_orders) { "hello" }
@@ -6,7 +6,7 @@ require 'worker_roulette/version'
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = 'nexia_worker_roulette'
8
8
  spec.version = WorkerRoulette::VERSION
9
- spec.authors = ['Paul Saieg']
9
+ spec.authors = ['Paul Saieg', 'James Barnard', 'Eric Schwartz']
10
10
  spec.email = ['classicist@gmail.com']
11
11
  spec.description = %q{Pub Sub Queue for Redis that ensures ordered processing}
12
12
  spec.summary = %q{Pub Sub Queue for Redis that ensures ordered processing}
metadata CHANGED
@@ -1,14 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nexia_worker_roulette
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Saieg
8
+ - James Barnard
9
+ - Eric Schwartz
8
10
  autorequire:
9
11
  bindir: bin
10
12
  cert_chain: []
11
- date: 2015-07-10 00:00:00.000000000 Z
13
+ date: 2015-07-13 00:00:00.000000000 Z
12
14
  dependencies:
13
15
  - !ruby/object:Gem::Dependency
14
16
  name: oj
@@ -246,7 +248,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
246
248
  version: '0'
247
249
  requirements: []
248
250
  rubyforge_project:
249
- rubygems_version: 2.4.3
251
+ rubygems_version: 2.4.2
250
252
  signing_key:
251
253
  specification_version: 4
252
254
  summary: Pub Sub Queue for Redis that ensures ordered processing