nexia_worker_roulette 0.2.3 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/worker_roulette/monkey_patches.rb +16 -0
- data/lib/worker_roulette/version.rb +1 -1
- data/lib/worker_roulette.rb +2 -0
- data/spec/unit/worker_roulette_spec.rb +95 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3c854aeeb7a69a210ae9c85fb1ec0e61344f5f14
|
4
|
+
data.tar.gz: 47b8208a2cd022894dd6ff8a87e2d31879be89b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f907b5b5cbd2f4f843b14af116e5f3ea62a14a08f196fc3bb48c4ae0b9c7b42d6bf1ea79c679793d075beb8b06e7b74166b0bbd14acebc0dbc0e3127b65af399
|
7
|
+
data.tar.gz: daf34a515f98cba866824c1cff8002881f6a5348b4b9cf8cfb08ca46bb4fa819d40c7a6cad215d7a058faf592fea444c1d31fbb957452d35a955d30521a8ff50
|
@@ -7,3 +7,19 @@ class String
|
|
7
7
|
downcase
|
8
8
|
end
|
9
9
|
end
|
10
|
+
class Hash
|
11
|
+
# FROM: File activesupport/lib/active_support/core_ext/hash/keys.rb, line 50
|
12
|
+
# made recursive by JB
|
13
|
+
def recursive_symbolize_keys!
|
14
|
+
recursive_transform_keys!{ |key| key.to_sym rescue key }
|
15
|
+
end
|
16
|
+
|
17
|
+
def recursive_transform_keys!
|
18
|
+
return enum_for(:transform_keys!) unless block_given?
|
19
|
+
keys.each do |key|
|
20
|
+
value = delete(key)
|
21
|
+
self[yield(key)] = value.kind_of?(Hash) ? value.recursive_symbolize_keys! : value
|
22
|
+
end
|
23
|
+
self
|
24
|
+
end
|
25
|
+
end
|
data/lib/worker_roulette.rb
CHANGED
@@ -57,6 +57,7 @@ module WorkerRoulette
|
|
57
57
|
attr_reader :preprocessors
|
58
58
|
|
59
59
|
def initialize(config = {})
|
60
|
+
config.recursive_symbolize_keys!
|
60
61
|
@redis_config = DEFAULT_REDIS_CONFIG.merge(config)
|
61
62
|
@pool_config = { size: @redis_config.delete(:pool_size), timeout: @redis_config.delete(:timeout) }
|
62
63
|
@evented = @redis_config.delete(:evented)
|
@@ -76,6 +77,7 @@ module WorkerRoulette
|
|
76
77
|
QueueMetricTracker.configure(
|
77
78
|
{
|
78
79
|
server_name: `hostname`.chomp,
|
80
|
+
granularity: config[:granularity],
|
79
81
|
metric_host: config[:metric_host],
|
80
82
|
metric_host_port: config[:metric_host_port],
|
81
83
|
metrics: config[:metrics]
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module WorkerRoulette
|
4
|
+
describe WorkerRoulette do
|
5
|
+
DEFAULT_POLLING_TIME = 2
|
6
|
+
let(:redis_host) { "redis_host" }
|
7
|
+
let(:db) { 7 }
|
8
|
+
let(:metric_host_name) { "localhost" }
|
9
|
+
let(:metric_port) { 7777 }
|
10
|
+
let(:granularity) { 10 }
|
11
|
+
let(:server_name) { `hostname`.chomp || "hostname" }
|
12
|
+
|
13
|
+
let(:symbolized_config) { {
|
14
|
+
host: redis_host,
|
15
|
+
db: db,
|
16
|
+
metric_tracker: {
|
17
|
+
metric_host: metric_host_name,
|
18
|
+
metric_host_port: metric_port,
|
19
|
+
granularity: granularity,
|
20
|
+
metrics: {
|
21
|
+
batch_size: true,
|
22
|
+
queue_depth: true,
|
23
|
+
queue_latency: true
|
24
|
+
}
|
25
|
+
}
|
26
|
+
} }
|
27
|
+
|
28
|
+
let(:stringified_config) { {
|
29
|
+
"host" => redis_host,
|
30
|
+
"db" => 7,
|
31
|
+
"metric_tracker" => {
|
32
|
+
"metric_host" => metric_host_name,
|
33
|
+
"metric_host_port" => metric_port,
|
34
|
+
"granularity" => granularity,
|
35
|
+
"metrics" => {
|
36
|
+
"batch_size" => true,
|
37
|
+
"queue_depth" => true,
|
38
|
+
"queue_latency" => true,
|
39
|
+
}
|
40
|
+
}
|
41
|
+
} }
|
42
|
+
|
43
|
+
let(:redis_config) { {
|
44
|
+
host: redis_host,
|
45
|
+
driver: :hiredis,
|
46
|
+
port: 6379,
|
47
|
+
db: db
|
48
|
+
} }
|
49
|
+
|
50
|
+
let(:metrics_config) { {
|
51
|
+
granularity: granularity,
|
52
|
+
metric_host: metric_host_name,
|
53
|
+
metric_host_port: metric_port,
|
54
|
+
metrics: {
|
55
|
+
batch_size: true,
|
56
|
+
queue_depth: true,
|
57
|
+
queue_latency: true
|
58
|
+
}
|
59
|
+
} }
|
60
|
+
|
61
|
+
let(:metric_host) { {
|
62
|
+
host_ip: "127.0.0.1",
|
63
|
+
host_port: metric_port
|
64
|
+
} }
|
65
|
+
|
66
|
+
let(:metric_tracker_config) { metrics_config.delete_if{ |k| k == :metric_host_port }.merge(metric_host: metric_host).merge(server_name: server_name) }
|
67
|
+
|
68
|
+
subject(:worker_roulette) { WorkerRoulette.start(options) }
|
69
|
+
|
70
|
+
describe "initialize" do
|
71
|
+
context "when config hash has symbol keys" do
|
72
|
+
let(:options) { symbolized_config }
|
73
|
+
|
74
|
+
it "successfully interprets the config hash" do
|
75
|
+
expect(subject.redis_config.delete_if{ |k| k == :metric_tracker }).to eq(redis_config)
|
76
|
+
end
|
77
|
+
|
78
|
+
it "successfully interprets the metrics hash" do
|
79
|
+
expect(QueueMetricTracker.config).to eq(metric_tracker_config)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
context "when config hash has string keys" do
|
84
|
+
let(:options) { stringified_config }
|
85
|
+
it "successfully interprets the config hash" do
|
86
|
+
expect(subject.redis_config.delete_if{ |k| k == :metric_tracker }).to eq(redis_config)
|
87
|
+
end
|
88
|
+
|
89
|
+
it "successfully interprets the metrics hash" do
|
90
|
+
expect(QueueMetricTracker.config).to eq(metric_tracker_config)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Saieg
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2015-08-
|
13
|
+
date: 2015-08-05 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: oj
|
@@ -235,6 +235,7 @@ files:
|
|
235
235
|
- spec/unit/queue_metric_tracker_spec.rb
|
236
236
|
- spec/unit/readlock_spec.rb
|
237
237
|
- spec/unit/stat_calculator_spec.rb
|
238
|
+
- spec/unit/worker_roulette_spec.rb
|
238
239
|
- worker_roulette.gemspec
|
239
240
|
homepage: https://github.com/nexiahome/worker_roulette
|
240
241
|
licenses: []
|
@@ -273,3 +274,4 @@ test_files:
|
|
273
274
|
- spec/unit/queue_metric_tracker_spec.rb
|
274
275
|
- spec/unit/readlock_spec.rb
|
275
276
|
- spec/unit/stat_calculator_spec.rb
|
277
|
+
- spec/unit/worker_roulette_spec.rb
|