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 +4 -4
- data/lib/worker_roulette/queue_latency_tracker.rb +2 -1
- data/lib/worker_roulette/version.rb +1 -1
- data/lib/worker_roulette.rb +5 -1
- data/spec/integration/evented_worker_roulette_spec.rb +10 -2
- data/spec/integration/worker_roulette_spec.rb +26 -9
- data/spec/unit/readlock_spec.rb +8 -2
- data/worker_roulette.gemspec +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 485a631bf7929866af1715af3649ce0ef5abcd49
|
4
|
+
data.tar.gz: 562bdf170332fe368447e8c2dac02ec9a6fbabd8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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!(
|
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
|
data/lib/worker_roulette.rb
CHANGED
@@ -76,7 +76,7 @@ module WorkerRoulette
|
|
76
76
|
QueueLatencyTracker.configure(
|
77
77
|
{
|
78
78
|
server_name: `hostname`.chomp,
|
79
|
-
logstash_server_ip:
|
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(:
|
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
|
-
|
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(:
|
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
|
-
|
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
|
-
|
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
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
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
|
|
data/spec/unit/readlock_spec.rb
CHANGED
@@ -1,8 +1,14 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
module WorkerRoulette
|
4
|
-
|
5
|
-
let(:
|
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" }
|
data/worker_roulette.gemspec
CHANGED
@@ -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.
|
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-
|
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.
|
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
|