bumbleworks 0.0.89 → 0.0.90
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/bumbleworks/process.rb +4 -4
- data/lib/bumbleworks/version.rb +1 -1
- data/lib/bumbleworks/worker.rb +9 -73
- data/lib/bumbleworks/worker/info.rb +176 -0
- data/lib/bumbleworks/worker/proxy.rb +25 -0
- data/spec/lib/bumbleworks/process_spec.rb +4 -4
- data/spec/lib/bumbleworks/task_spec.rb +1 -1
- data/spec/lib/bumbleworks/worker/info_spec.rb +205 -0
- data/spec/lib/bumbleworks/worker/proxy_spec.rb +22 -0
- data/spec/lib/bumbleworks/worker_spec.rb +0 -39
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 28e8c92dc9de4fb9204a5b2348565a1d47d960b0
|
4
|
+
data.tar.gz: 6fb4c218cbe093862c9a61b418aa32b2a4594238
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: abb2292ed00b147314a70f633619c62e77a20e5ccd7bd73c4cb91e2131c8e58b5764dc3a38a4bb840079cc51859618a654b1ef5ae32270ea8f58a7429f5a8fce
|
7
|
+
data.tar.gz: b5fee4533318cea0829dcb9e691d6ccea143e94157730e89fccae34dbeac3513f1620d39b8f46f876f18230d0361fbb53cd5817c5ed861224b6fc78241019285
|
data/lib/bumbleworks/process.rb
CHANGED
@@ -133,12 +133,12 @@ module Bumbleworks
|
|
133
133
|
subscribed_events.include? event.to_s
|
134
134
|
end
|
135
135
|
|
136
|
-
def kill!
|
137
|
-
Bumbleworks.kill_process!(wfid)
|
136
|
+
def kill!(options = {})
|
137
|
+
Bumbleworks.kill_process!(wfid, options)
|
138
138
|
end
|
139
139
|
|
140
|
-
def cancel!
|
141
|
-
Bumbleworks.cancel_process!(wfid)
|
140
|
+
def cancel!(options = {})
|
141
|
+
Bumbleworks.cancel_process!(wfid, options)
|
142
142
|
end
|
143
143
|
|
144
144
|
def process_status
|
data/lib/bumbleworks/version.rb
CHANGED
data/lib/bumbleworks/worker.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
require 'securerandom'
|
2
|
+
require_relative "worker/info"
|
2
3
|
|
3
4
|
class Bumbleworks::Worker < Ruote::Worker
|
4
5
|
class WorkerStateNotChanged < StandardError; end
|
5
6
|
|
6
|
-
attr_reader :id
|
7
|
+
attr_reader :id, :pid, :ip, :hostname, :system, :launched_at
|
7
8
|
|
8
9
|
class << self
|
9
10
|
def info
|
@@ -36,29 +37,6 @@ class Bumbleworks::Worker < Ruote::Worker
|
|
36
37
|
}
|
37
38
|
end
|
38
39
|
|
39
|
-
def forget_worker(id_to_delete)
|
40
|
-
purge_worker_info do |id, info|
|
41
|
-
id == id_to_delete
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def purge_stale_worker_info
|
46
|
-
purge_worker_info do |id, info|
|
47
|
-
info['state'].nil? || info['state'] == 'stopped'
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def purge_worker_info(&block)
|
52
|
-
doc = Bumbleworks.dashboard.storage.get('variables', 'workers')
|
53
|
-
return unless doc
|
54
|
-
doc['workers'] = doc['workers'].reject { |id, info|
|
55
|
-
block.call(id, info)
|
56
|
-
}
|
57
|
-
result = Bumbleworks.dashboard.storage.put(doc)
|
58
|
-
purge_stale_worker_info if result
|
59
|
-
info
|
60
|
-
end
|
61
|
-
|
62
40
|
def change_worker_state(new_state, options = {})
|
63
41
|
with_worker_state_enabled do
|
64
42
|
Bumbleworks.dashboard.worker_state = new_state
|
@@ -91,7 +69,14 @@ class Bumbleworks::Worker < Ruote::Worker
|
|
91
69
|
|
92
70
|
def initialize(*args, &block)
|
93
71
|
super
|
72
|
+
@pid = Process.pid
|
94
73
|
@id = SecureRandom.uuid
|
74
|
+
@launched_at = Time.now
|
75
|
+
|
76
|
+
@ip = Ruote.local_ip
|
77
|
+
@hostname = Socket.gethostname
|
78
|
+
@system = `uname -a`.strip rescue nil
|
79
|
+
|
95
80
|
if @info
|
96
81
|
@info = Info.new(self)
|
97
82
|
save_info
|
@@ -117,53 +102,4 @@ class Bumbleworks::Worker < Ruote::Worker
|
|
117
102
|
def info
|
118
103
|
self.class.info[id]
|
119
104
|
end
|
120
|
-
|
121
|
-
class Info < Ruote::Worker::Info
|
122
|
-
def save
|
123
|
-
doc = @worker.storage.get('variables', 'workers') || {}
|
124
|
-
|
125
|
-
doc['type'] = 'variables'
|
126
|
-
doc['_id'] = 'workers'
|
127
|
-
|
128
|
-
now = Time.now
|
129
|
-
|
130
|
-
@msgs = @msgs.drop_while { |msg|
|
131
|
-
Time.parse(msg['processed_at']) < now - 3600
|
132
|
-
}
|
133
|
-
mm = @msgs.drop_while { |msg|
|
134
|
-
Time.parse(msg['processed_at']) < now - 60
|
135
|
-
}
|
136
|
-
|
137
|
-
hour_count = @msgs.size < 1 ? 1 : @msgs.size
|
138
|
-
minute_count = mm.size < 1 ? 1 : mm.size
|
139
|
-
|
140
|
-
(doc['workers'] ||= {})[@worker.id] = {
|
141
|
-
|
142
|
-
'class' => @worker.class.to_s,
|
143
|
-
'name' => @worker.name,
|
144
|
-
'ip' => @ip,
|
145
|
-
'hostname' => @hostname,
|
146
|
-
'pid' => $$,
|
147
|
-
'system' => @system,
|
148
|
-
'put_at' => Ruote.now_to_utc_s,
|
149
|
-
'uptime' => Time.now - @since,
|
150
|
-
'state' => @worker.state,
|
151
|
-
|
152
|
-
'processed_last_minute' =>
|
153
|
-
mm.size,
|
154
|
-
'wait_time_last_minute' =>
|
155
|
-
mm.inject(0.0) { |s, m| s + m['wait_time'] } / minute_count.to_f,
|
156
|
-
'processed_last_hour' =>
|
157
|
-
@msgs.size,
|
158
|
-
'wait_time_last_hour' =>
|
159
|
-
@msgs.inject(0.0) { |s, m| s + m['wait_time'] } / hour_count.to_f
|
160
|
-
}
|
161
|
-
|
162
|
-
r = @worker.storage.put(doc)
|
163
|
-
|
164
|
-
@last_save = Time.now
|
165
|
-
|
166
|
-
save if r != nil
|
167
|
-
end
|
168
|
-
end
|
169
105
|
end
|
@@ -0,0 +1,176 @@
|
|
1
|
+
require_relative "proxy"
|
2
|
+
|
3
|
+
class Bumbleworks::Worker < Ruote::Worker
|
4
|
+
class Info < Ruote::Worker::Info
|
5
|
+
attr_reader :worker
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def raw_hash
|
9
|
+
Bumbleworks.dashboard.worker_info || {}
|
10
|
+
end
|
11
|
+
|
12
|
+
def all
|
13
|
+
raw_hash.map { |k, v|
|
14
|
+
from_hash(v.merge('id' => k))
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
def where(options)
|
19
|
+
filter_proc = proc { |worker|
|
20
|
+
options.all? { |k, v|
|
21
|
+
worker.send(k.to_sym) == v
|
22
|
+
}
|
23
|
+
}
|
24
|
+
filter(&filter_proc)
|
25
|
+
end
|
26
|
+
|
27
|
+
def filter
|
28
|
+
return [] unless block_given?
|
29
|
+
all.select { |info| yield info.worker }
|
30
|
+
end
|
31
|
+
|
32
|
+
def [](worker_id)
|
33
|
+
from_hash(raw_hash[worker_id].merge('id' => worker_id))
|
34
|
+
end
|
35
|
+
|
36
|
+
def from_hash(hash)
|
37
|
+
new(Bumbleworks::Worker::Proxy.new(hash))
|
38
|
+
end
|
39
|
+
|
40
|
+
def forget_worker(id_to_delete)
|
41
|
+
purge_worker_info do |id, info|
|
42
|
+
id == id_to_delete
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def purge_stale_worker_info
|
47
|
+
purge_worker_info do |id, info|
|
48
|
+
info['state'].nil? || info['state'] == 'stopped'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def purge_worker_info(&block)
|
53
|
+
doc = Bumbleworks.dashboard.storage.get('variables', 'workers')
|
54
|
+
return unless doc
|
55
|
+
doc['workers'] = doc['workers'].reject { |id, info|
|
56
|
+
block.call(id, info)
|
57
|
+
}
|
58
|
+
result = Bumbleworks.dashboard.storage.put(doc)
|
59
|
+
purge_stale_worker_info if result
|
60
|
+
all
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def ==(other)
|
65
|
+
other.is_a?(Bumbleworks::Worker::Info) &&
|
66
|
+
other.worker == worker
|
67
|
+
end
|
68
|
+
|
69
|
+
def raw_hash
|
70
|
+
self.class.raw_hash[worker.id]
|
71
|
+
end
|
72
|
+
|
73
|
+
def updated_at
|
74
|
+
Time.parse(raw_hash['put_at'])
|
75
|
+
end
|
76
|
+
|
77
|
+
def updated_since?(latest_time)
|
78
|
+
updated_at >= latest_time
|
79
|
+
end
|
80
|
+
|
81
|
+
def updated_recently?(options = {})
|
82
|
+
options[:seconds_ago] ||= Bumbleworks.timeout
|
83
|
+
latest_time = Time.now - options[:seconds_ago]
|
84
|
+
updated_since?(latest_time)
|
85
|
+
end
|
86
|
+
|
87
|
+
def responding?(options = {})
|
88
|
+
options[:since] ||= Time.now - Bumbleworks.timeout
|
89
|
+
Bumbleworks::Worker.with_worker_state_enabled do
|
90
|
+
Bumbleworks::Support.wait_until(options) do
|
91
|
+
updated_since?(options[:since])
|
92
|
+
end
|
93
|
+
end
|
94
|
+
true
|
95
|
+
rescue Bumbleworks::Support::WaitTimeout
|
96
|
+
false
|
97
|
+
end
|
98
|
+
|
99
|
+
def stalling?
|
100
|
+
!responding?
|
101
|
+
end
|
102
|
+
|
103
|
+
def storage
|
104
|
+
@worker.storage || Bumbleworks.dashboard.storage
|
105
|
+
end
|
106
|
+
|
107
|
+
def initialize(worker)
|
108
|
+
@worker = worker
|
109
|
+
@last_save = Time.now - 2 * 60
|
110
|
+
|
111
|
+
@msgs = [] unless worker.is_a?(Bumbleworks::Worker::Proxy)
|
112
|
+
end
|
113
|
+
|
114
|
+
def worker_info_document
|
115
|
+
doc = storage.get('variables', 'workers') || {}
|
116
|
+
|
117
|
+
doc['type'] = 'variables'
|
118
|
+
doc['_id'] = 'workers'
|
119
|
+
doc['workers'] ||= {}
|
120
|
+
doc
|
121
|
+
end
|
122
|
+
|
123
|
+
def save
|
124
|
+
doc = worker_info_document
|
125
|
+
|
126
|
+
worker_info_hash = doc['workers'][@worker.id] || {}
|
127
|
+
|
128
|
+
worker_info_hash.merge!({
|
129
|
+
'worker_id' => @worker.id,
|
130
|
+
'class' => @worker.class.to_s,
|
131
|
+
'name' => @worker.name,
|
132
|
+
'ip' => @worker.ip,
|
133
|
+
'hostname' => @worker.hostname,
|
134
|
+
'pid' => @worker.pid,
|
135
|
+
'system' => @worker.system,
|
136
|
+
'put_at' => Ruote.now_to_utc_s,
|
137
|
+
'uptime' => Time.now - @worker.launched_at,
|
138
|
+
'launched_at' => @worker.launched_at,
|
139
|
+
'state' => @worker.state
|
140
|
+
})
|
141
|
+
|
142
|
+
if defined?(@msgs)
|
143
|
+
now = Time.now
|
144
|
+
|
145
|
+
@msgs = @msgs.drop_while { |msg|
|
146
|
+
Time.parse(msg['processed_at']) < now - 3600
|
147
|
+
}
|
148
|
+
mm = @msgs.drop_while { |msg|
|
149
|
+
Time.parse(msg['processed_at']) < now - 60
|
150
|
+
}
|
151
|
+
|
152
|
+
hour_count = @msgs.size < 1 ? 1 : @msgs.size
|
153
|
+
minute_count = mm.size < 1 ? 1 : mm.size
|
154
|
+
|
155
|
+
worker_info_hash.merge!({
|
156
|
+
'processed_last_minute' =>
|
157
|
+
mm.size,
|
158
|
+
'wait_time_last_minute' =>
|
159
|
+
mm.inject(0.0) { |s, m| s + m['wait_time'] } / minute_count.to_f,
|
160
|
+
'processed_last_hour' =>
|
161
|
+
@msgs.size,
|
162
|
+
'wait_time_last_hour' =>
|
163
|
+
@msgs.inject(0.0) { |s, m| s + m['wait_time'] } / hour_count.to_f
|
164
|
+
})
|
165
|
+
end
|
166
|
+
|
167
|
+
doc['workers'][@worker.id] = worker_info_hash
|
168
|
+
|
169
|
+
r = storage.put(doc)
|
170
|
+
|
171
|
+
@last_save = Time.now
|
172
|
+
|
173
|
+
save if r != nil
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class Bumbleworks::Worker < Ruote::Worker
|
2
|
+
class Proxy
|
3
|
+
ProxiedAttributes = [
|
4
|
+
:id, :pid, :ip, :hostname, :system, :launched_at, :state, :name, :class
|
5
|
+
]
|
6
|
+
|
7
|
+
attr_reader *(ProxiedAttributes - [:launched_at])
|
8
|
+
attr_reader :raw_hash
|
9
|
+
|
10
|
+
def initialize(attributes)
|
11
|
+
@raw_hash = attributes
|
12
|
+
ProxiedAttributes.each do |key|
|
13
|
+
instance_variable_set(:"@#{key}", attributes[key.to_s])
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def launched_at
|
18
|
+
Time.parse(@launched_at)
|
19
|
+
end
|
20
|
+
|
21
|
+
def ==(other)
|
22
|
+
raw_hash == other.raw_hash
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -342,16 +342,16 @@ describe Bumbleworks::Process do
|
|
342
342
|
describe '#kill!' do
|
343
343
|
it 'kills process' do
|
344
344
|
bp = described_class.new('frogheads')
|
345
|
-
expect(Bumbleworks).to receive(:kill_process!).with('frogheads')
|
346
|
-
bp.kill!
|
345
|
+
expect(Bumbleworks).to receive(:kill_process!).with('frogheads', :an => :option)
|
346
|
+
bp.kill!(:an => :option)
|
347
347
|
end
|
348
348
|
end
|
349
349
|
|
350
350
|
describe '#cancel!' do
|
351
351
|
it 'cancels process' do
|
352
352
|
bp = described_class.new('frogheads')
|
353
|
-
expect(Bumbleworks).to receive(:cancel_process!).with('frogheads')
|
354
|
-
bp.cancel!
|
353
|
+
expect(Bumbleworks).to receive(:cancel_process!).with('frogheads', :an => :option)
|
354
|
+
bp.cancel!(:an => :option)
|
355
355
|
end
|
356
356
|
end
|
357
357
|
|
@@ -257,7 +257,7 @@ describe Bumbleworks::Task do
|
|
257
257
|
context 'by params' do
|
258
258
|
before(:each) do
|
259
259
|
Bumbleworks.launch!('emergency_hamster_bullet')
|
260
|
-
Bumbleworks.dashboard.wait_for(:
|
260
|
+
Bumbleworks.dashboard.wait_for(:rhubarb)
|
261
261
|
end
|
262
262
|
|
263
263
|
describe '.order_by_param' do
|
@@ -0,0 +1,205 @@
|
|
1
|
+
describe Bumbleworks::Worker::Info do
|
2
|
+
let(:context) { Bumbleworks.dashboard.context }
|
3
|
+
let(:proxy) {
|
4
|
+
Bumbleworks::Worker::Proxy.new(
|
5
|
+
'class' => :f_class,
|
6
|
+
'pid' => :f_pid,
|
7
|
+
'name' => :f_name,
|
8
|
+
'id' => :f_id,
|
9
|
+
'state' => :f_state,
|
10
|
+
'ip' => :f_ip,
|
11
|
+
'hostname' => :f_hostname,
|
12
|
+
'system' => :f_system,
|
13
|
+
'launched_at' => :f_launched_at
|
14
|
+
)
|
15
|
+
}
|
16
|
+
subject { described_class.new(proxy) }
|
17
|
+
|
18
|
+
describe '.raw_hash' do
|
19
|
+
it 'returns Bumbleworks.dashboard.worker_info' do
|
20
|
+
allow(Bumbleworks.dashboard).to receive(:worker_info).and_return(:bontron)
|
21
|
+
expect(described_class.raw_hash).to eq(:bontron)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'returns empty hash if worker_info is nil' do
|
25
|
+
allow(Bumbleworks.dashboard).to receive(:worker_info).and_return(nil)
|
26
|
+
expect(described_class.raw_hash).to eq({})
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '.from_hash' do
|
31
|
+
it 'returns an info object using a proxy worker with given attributes' do
|
32
|
+
hash = {
|
33
|
+
'class' => :f_class,
|
34
|
+
'pid' => :f_pid,
|
35
|
+
'name' => :f_name,
|
36
|
+
'id' => :f_id,
|
37
|
+
'state' => :f_state,
|
38
|
+
'ip' => :f_ip,
|
39
|
+
'hostname' => :f_hostname,
|
40
|
+
'system' => :f_system,
|
41
|
+
'launched_at' => :f_launched_at
|
42
|
+
}
|
43
|
+
allow(described_class).to receive(:new).
|
44
|
+
with(proxy).
|
45
|
+
and_return(:proxy)
|
46
|
+
expect(described_class.from_hash(hash)).to eq(:proxy)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context 'with fake raw hash' do
|
51
|
+
before(:each) do
|
52
|
+
raw_hash = {
|
53
|
+
'f_id' => { 'foo' => 1 },
|
54
|
+
'b_id' => { 'bar' => 1 }
|
55
|
+
}
|
56
|
+
allow(described_class).to receive(:raw_hash).
|
57
|
+
and_return(raw_hash)
|
58
|
+
end
|
59
|
+
|
60
|
+
describe '.[]' do
|
61
|
+
it 'calls from_hash with raw data for given worker id' do
|
62
|
+
allow(described_class).to receive(:from_hash).
|
63
|
+
with({ 'foo' => 1, 'id' => 'f_id' }).and_return(:foo_info)
|
64
|
+
expect(described_class['f_id']).to eq(:foo_info)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe '.all' do
|
69
|
+
it 'converts raw hash into info instances' do
|
70
|
+
allow(described_class).to receive(:from_hash).
|
71
|
+
with({ 'foo' => 1, 'id' => 'f_id'}).and_return(:foo_info)
|
72
|
+
allow(described_class).to receive(:from_hash).
|
73
|
+
with({ 'bar' => 1, 'id' => 'b_id'}).and_return(:bar_info)
|
74
|
+
expect(described_class.all).to match_array([:foo_info, :bar_info])
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
context 'with multiple workers' do
|
80
|
+
let!(:workers) {
|
81
|
+
3.times.map { |i|
|
82
|
+
worker = Bumbleworks::Worker.new(context)
|
83
|
+
worker.run_in_thread
|
84
|
+
worker
|
85
|
+
}
|
86
|
+
}
|
87
|
+
|
88
|
+
describe '.filter' do
|
89
|
+
it 'returns info objects for workers that pass given block' do
|
90
|
+
expect(described_class.filter { |worker|
|
91
|
+
worker.id != workers[0].id
|
92
|
+
}).to match_array([
|
93
|
+
described_class[workers[1].id],
|
94
|
+
described_class[workers[2].id]
|
95
|
+
])
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe '.where' do
|
100
|
+
it 'returns info objects for workers that match given criteria' do
|
101
|
+
expect(described_class.where(:id => workers[0].id)).
|
102
|
+
to match_array([described_class[workers[0].id]])
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
describe '.forget_worker' do
|
107
|
+
it 'deletes worker info for given worker id' do
|
108
|
+
described_class.forget_worker(workers[1].id)
|
109
|
+
expect(described_class.raw_hash.keys).not_to include(workers[1].id)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
describe '.purge_stale_worker_info' do
|
114
|
+
it 'deletes all worker info where state is stopped or nil' do
|
115
|
+
workers[0].shutdown
|
116
|
+
workers[1].instance_variable_set(:@state, nil)
|
117
|
+
workers[1].instance_variable_get(:@info).save
|
118
|
+
remaining_worker_info = described_class[workers[2].id]
|
119
|
+
described_class.purge_stale_worker_info
|
120
|
+
expect(described_class.all).to eq([remaining_worker_info])
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'returns without issue if no workers' do
|
124
|
+
doc = Bumbleworks.dashboard.storage.get('variables', 'workers')
|
125
|
+
Bumbleworks.dashboard.storage.delete(doc)
|
126
|
+
described_class.purge_stale_worker_info
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
describe "#updated_at" do
|
132
|
+
it "returns parsed put_at from raw hash for worker" do
|
133
|
+
allow(subject).to receive(:raw_hash).and_return({
|
134
|
+
'put_at' => '2015-10-12 11:15:30'
|
135
|
+
})
|
136
|
+
expect(subject.updated_at).to eq(Time.parse('2015-10-12 11:15:30'))
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
describe "#updated_since?" do
|
141
|
+
let(:frozen_time) { Time.now }
|
142
|
+
|
143
|
+
it "returns true if updated_at after given time" do
|
144
|
+
allow(subject).to receive(:updated_at).and_return(frozen_time - 2)
|
145
|
+
expect(subject).to be_updated_since(frozen_time - 3)
|
146
|
+
end
|
147
|
+
|
148
|
+
it "returns false if updated_at before given time" do
|
149
|
+
allow(subject).to receive(:updated_at).and_return(frozen_time - 3)
|
150
|
+
expect(subject).not_to be_updated_since(frozen_time - 2)
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
describe "#updated_recently?" do
|
155
|
+
before(:each) do
|
156
|
+
allow(Bumbleworks).to receive(:timeout).and_return(3)
|
157
|
+
end
|
158
|
+
|
159
|
+
it "returns true if updated_at is no more than Bumbleworks.timeout seconds ago" do
|
160
|
+
allow(subject).to receive(:updated_at).and_return(Time.now - 2)
|
161
|
+
expect(subject).to be_updated_recently
|
162
|
+
end
|
163
|
+
|
164
|
+
it "returns false if updated_at is more than Bumbleworks.timeout seconds ago" do
|
165
|
+
allow(subject).to receive(:updated_at).and_return(Time.now - 4)
|
166
|
+
expect(subject).not_to be_updated_recently
|
167
|
+
end
|
168
|
+
|
169
|
+
it "allows override of how many seconds ago" do
|
170
|
+
allow(subject).to receive(:updated_at).and_return(Time.now - 15)
|
171
|
+
expect(subject).to be_updated_recently(seconds_ago: 20)
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
describe "#raw_hash" do
|
176
|
+
it "returns value from worker_info hash at key of worker id" do
|
177
|
+
allow(described_class).to receive(:raw_hash).and_return({
|
178
|
+
:f_id => :foo_hash,
|
179
|
+
:b_id => :bar_hash
|
180
|
+
})
|
181
|
+
expect(subject.raw_hash).to eq(:foo_hash)
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
describe "#responding?" do
|
186
|
+
it "returns true if updated_recently? returns true in time" do
|
187
|
+
allow(subject).to receive(:updated_since?).and_return(true)
|
188
|
+
expect(subject).to be_responding
|
189
|
+
end
|
190
|
+
|
191
|
+
it "returns false if updated_recently? does not return true in time" do
|
192
|
+
allow(subject).to receive(:updated_since?).and_raise(Bumbleworks::Support::WaitTimeout)
|
193
|
+
expect(subject).not_to be_responding
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
describe "#stalling?" do
|
198
|
+
it "returns inverse of #responding?" do
|
199
|
+
allow(subject).to receive(:responding?).and_return(true)
|
200
|
+
expect(subject).not_to be_stalling
|
201
|
+
allow(subject).to receive(:responding?).and_return(false)
|
202
|
+
expect(subject).to be_stalling
|
203
|
+
end
|
204
|
+
end
|
205
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
describe Bumbleworks::Worker::Proxy do
|
2
|
+
subject {
|
3
|
+
described_class.new(
|
4
|
+
'class' => :f_class,
|
5
|
+
'pid' => :f_pid,
|
6
|
+
'name' => :f_name,
|
7
|
+
'id' => :f_id,
|
8
|
+
'state' => :f_state,
|
9
|
+
'ip' => :f_ip,
|
10
|
+
'hostname' => :f_hostname,
|
11
|
+
'system' => :f_system,
|
12
|
+
'launched_at' => :f_launched_at
|
13
|
+
)
|
14
|
+
}
|
15
|
+
|
16
|
+
describe "#launched_at" do
|
17
|
+
it "returns initialized launched_at string parsed as Time" do
|
18
|
+
allow(Time).to receive(:parse).with(:f_launched_at).and_return(:a_time)
|
19
|
+
expect(subject.launched_at).to eq(:a_time)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -45,25 +45,6 @@ describe Bumbleworks::Worker do
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
-
describe '.info' do
|
49
|
-
it 'returns Bumbleworks.dashboard.worker_info' do
|
50
|
-
allow(Bumbleworks.dashboard).to receive(:worker_info).and_return(:bontron)
|
51
|
-
expect(described_class.info).to eq(:bontron)
|
52
|
-
end
|
53
|
-
|
54
|
-
it 'returns empty hash if worker_info is nil' do
|
55
|
-
allow(Bumbleworks.dashboard).to receive(:worker_info).and_return(nil)
|
56
|
-
expect(described_class.info).to eq({})
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
describe '.forget_worker' do
|
61
|
-
it 'deletes worker info for given worker id' do
|
62
|
-
described_class.forget_worker(workers[1].id)
|
63
|
-
expect(described_class.info.keys).not_to include(workers[1].id)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
48
|
describe '.refresh_worker_info' do
|
68
49
|
it 'times out if info is not updated in time' do
|
69
50
|
allow(described_class).to receive(:info).and_return({
|
@@ -91,26 +72,6 @@ describe Bumbleworks::Worker do
|
|
91
72
|
end
|
92
73
|
end
|
93
74
|
|
94
|
-
describe '.purge_stale_worker_info' do
|
95
|
-
it 'deletes all worker info where state is stopped or nil' do
|
96
|
-
subject.run_in_thread
|
97
|
-
workers[0].shutdown
|
98
|
-
workers[1].instance_variable_set(:@state, nil)
|
99
|
-
workers[1].instance_variable_get(:@info).save
|
100
|
-
subject_info = described_class.info[subject.id]
|
101
|
-
described_class.purge_stale_worker_info
|
102
|
-
expect(described_class.info).to eq({
|
103
|
-
subject.id => subject_info
|
104
|
-
})
|
105
|
-
end
|
106
|
-
|
107
|
-
it 'returns without issue if no workers' do
|
108
|
-
doc = Bumbleworks.dashboard.storage.get('variables', 'workers')
|
109
|
-
Bumbleworks.dashboard.storage.delete(doc)
|
110
|
-
described_class.purge_stale_worker_info
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
75
|
describe '.change_worker_state' do
|
115
76
|
it 'changes state of all workers' do
|
116
77
|
expect(workers.map(&:state).uniq).to eq(['running'])
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bumbleworks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.90
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Maher Hawash
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date:
|
14
|
+
date: 2015-03-11 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: ruote
|
@@ -183,6 +183,8 @@ files:
|
|
183
183
|
- lib/bumbleworks/user.rb
|
184
184
|
- lib/bumbleworks/version.rb
|
185
185
|
- lib/bumbleworks/worker.rb
|
186
|
+
- lib/bumbleworks/worker/info.rb
|
187
|
+
- lib/bumbleworks/worker/proxy.rb
|
186
188
|
- lib/bumbleworks/workitem.rb
|
187
189
|
- lib/bumbleworks/workitem_entity_storage.rb
|
188
190
|
- lib/tasks/bumbleworks.rake
|
@@ -236,6 +238,8 @@ files:
|
|
236
238
|
- spec/lib/bumbleworks/tracker_spec.rb
|
237
239
|
- spec/lib/bumbleworks/tree_builder_spec.rb
|
238
240
|
- spec/lib/bumbleworks/user_spec.rb
|
241
|
+
- spec/lib/bumbleworks/worker/info_spec.rb
|
242
|
+
- spec/lib/bumbleworks/worker/proxy_spec.rb
|
239
243
|
- spec/lib/bumbleworks/worker_spec.rb
|
240
244
|
- spec/lib/bumbleworks/workitem_entity_storage_spec.rb
|
241
245
|
- spec/lib/bumbleworks/workitem_spec.rb
|
@@ -320,6 +324,8 @@ test_files:
|
|
320
324
|
- spec/lib/bumbleworks/tracker_spec.rb
|
321
325
|
- spec/lib/bumbleworks/tree_builder_spec.rb
|
322
326
|
- spec/lib/bumbleworks/user_spec.rb
|
327
|
+
- spec/lib/bumbleworks/worker/info_spec.rb
|
328
|
+
- spec/lib/bumbleworks/worker/proxy_spec.rb
|
323
329
|
- spec/lib/bumbleworks/worker_spec.rb
|
324
330
|
- spec/lib/bumbleworks/workitem_entity_storage_spec.rb
|
325
331
|
- spec/lib/bumbleworks/workitem_spec.rb
|