sbm 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -0
- data/lib/sbm/coordinator.rb +15 -0
- data/lib/sbm/runner.rb +17 -1
- data/lib/sbm/version.rb +1 -1
- data/spec/coordinator_spec.rb +50 -0
- data/spec/runner_spec.rb +31 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 682920a2da1dd9c3efc634ee2070c9a0b9dcedb7
|
4
|
+
data.tar.gz: f47948d0f6449f9961894d378d2819493dd17be6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f3e2224cd13f3c8e8d2dcfcd91424ae62d22c93ef53c8a4e387bd3b1449344279092b6e4b7c62e1e626718537420b389c774b3108d4ad0e415667019cad1bf3e
|
7
|
+
data.tar.gz: 45493771a9c013b235d933a4763cdd79dd435b6cb6ae91682ca9171981f4e5a50544febb922f2962bf92024f2ae725b21454a5c9269218e1120f5cc829adc7f9
|
data/README.md
CHANGED
@@ -46,6 +46,17 @@ Wait for simply checks the number of items in the completed set have the correct
|
|
46
46
|
|
47
47
|
Please note that by default it uses redis for this, so to change your default redis use `REDIS_URI`.
|
48
48
|
|
49
|
+
### Commands
|
50
|
+
|
51
|
+
* `sbm status` - Show status of all batches.
|
52
|
+
* `sbm start-batch batch-name` - Current worker starts the specified batch.
|
53
|
+
* `sbm complete-batch batch-name` - Current worker starts the specified batch.
|
54
|
+
* `sbm wait-for batch-name count` - Wait until `count` workers have completed `batch-name`.
|
55
|
+
* `sbm clear-batch batch-name` - Clear information for the given batch.
|
56
|
+
* `sbm clear-batches` - Clear all batch info.
|
57
|
+
* `sbm clear-workers` - Clear all worker info.
|
58
|
+
|
59
|
+
|
49
60
|
## Contributing
|
50
61
|
|
51
62
|
1. Fork it
|
data/lib/sbm/coordinator.rb
CHANGED
@@ -64,6 +64,21 @@ module SBM
|
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
67
|
+
def clear(batch)
|
68
|
+
redis.srem key(:batches), batch.to_s
|
69
|
+
redis.del key(:batches, batch, :completed)
|
70
|
+
redis.del key(:batches, batch, :started)
|
71
|
+
end
|
72
|
+
|
73
|
+
def clear_batches
|
74
|
+
batches.each { |b| clear b }
|
75
|
+
redis.del key(:batches)
|
76
|
+
end
|
77
|
+
|
78
|
+
def clear_workers
|
79
|
+
redis.del key(:workers)
|
80
|
+
end
|
81
|
+
|
67
82
|
private
|
68
83
|
|
69
84
|
def prepare(worker, batch)
|
data/lib/sbm/runner.rb
CHANGED
@@ -5,7 +5,10 @@ module SBM
|
|
5
5
|
'status' => '',
|
6
6
|
'wait-for' => 'batch-name worker-count',
|
7
7
|
'start-batch' => 'batch-name',
|
8
|
-
'complete-batch' => 'batch-name'
|
8
|
+
'complete-batch' => 'batch-name',
|
9
|
+
'clear-batch' => 'batch-name',
|
10
|
+
'clear-batches' => '',
|
11
|
+
'clear-workers' => ''
|
9
12
|
}
|
10
13
|
|
11
14
|
attr_reader :command, :args, :coordinator, :worker, :output, :error
|
@@ -68,6 +71,19 @@ module SBM
|
|
68
71
|
coordinator.complete batch, worker
|
69
72
|
end
|
70
73
|
|
74
|
+
def clear_batch
|
75
|
+
batch = extract_batch!
|
76
|
+
coordinator.clear batch
|
77
|
+
end
|
78
|
+
|
79
|
+
def clear_batches
|
80
|
+
coordinator.clear_batches
|
81
|
+
end
|
82
|
+
|
83
|
+
def clear_workers
|
84
|
+
coordinator.clear_workers
|
85
|
+
end
|
86
|
+
|
71
87
|
def usage(invalid_command = false)
|
72
88
|
if invalid_command
|
73
89
|
error.puts "Invalid / unknown command - must be one of #{USAGES.keys.join(", ")}"
|
data/lib/sbm/version.rb
CHANGED
data/spec/coordinator_spec.rb
CHANGED
@@ -117,4 +117,54 @@ describe SBM::Coordinator do
|
|
117
117
|
subject.wait_for batch_a, 3
|
118
118
|
end
|
119
119
|
|
120
|
+
it 'should support clearing a batch' do
|
121
|
+
subject.start batch_a, worker_a
|
122
|
+
subject.start batch_a, worker_b
|
123
|
+
subject.start batch_b, worker_c
|
124
|
+
subject.complete batch_b, worker_c
|
125
|
+
subject.batches.should =~ [batch_a, batch_b]
|
126
|
+
subject.started_workers_for_batch(batch_a).should =~ [worker_a, worker_b]
|
127
|
+
subject.started_workers_for_batch(batch_b).should =~ [worker_c]
|
128
|
+
subject.completed_workers_for_batch(batch_a).should =~ []
|
129
|
+
subject.completed_workers_for_batch(batch_b).should =~ [worker_c]
|
130
|
+
subject.clear batch_b
|
131
|
+
subject.batches.should =~ [batch_a]
|
132
|
+
subject.started_workers_for_batch(batch_a).should =~ [worker_a, worker_b]
|
133
|
+
subject.started_workers_for_batch(batch_b).should =~ []
|
134
|
+
subject.completed_workers_for_batch(batch_a).should =~ []
|
135
|
+
subject.completed_workers_for_batch(batch_b).should =~ []
|
136
|
+
subject.clear batch_a
|
137
|
+
subject.batches.should =~ []
|
138
|
+
subject.started_workers_for_batch(batch_a).should =~ []
|
139
|
+
subject.started_workers_for_batch(batch_b).should =~ []
|
140
|
+
subject.completed_workers_for_batch(batch_a).should =~ []
|
141
|
+
subject.completed_workers_for_batch(batch_b).should =~ []
|
142
|
+
end
|
143
|
+
|
144
|
+
it 'should support clearing all batches' do
|
145
|
+
subject.start batch_a, worker_a
|
146
|
+
subject.start batch_a, worker_b
|
147
|
+
subject.start batch_b, worker_c
|
148
|
+
subject.complete batch_b, worker_c
|
149
|
+
subject.batches.should =~ [batch_a, batch_b]
|
150
|
+
subject.started_workers_for_batch(batch_a).should =~ [worker_a, worker_b]
|
151
|
+
subject.started_workers_for_batch(batch_b).should =~ [worker_c]
|
152
|
+
subject.completed_workers_for_batch(batch_a).should =~ []
|
153
|
+
subject.completed_workers_for_batch(batch_b).should =~ [worker_c]
|
154
|
+
subject.clear_batches
|
155
|
+
subject.batches.should =~ []
|
156
|
+
subject.started_workers_for_batch(batch_a).should =~ []
|
157
|
+
subject.started_workers_for_batch(batch_b).should =~ []
|
158
|
+
subject.completed_workers_for_batch(batch_a).should =~ []
|
159
|
+
subject.completed_workers_for_batch(batch_b).should =~ []
|
160
|
+
end
|
161
|
+
|
162
|
+
it 'should support clear all workers' do
|
163
|
+
subject.start batch_a, worker_a
|
164
|
+
subject.start batch_a, worker_b
|
165
|
+
subject.workers.should =~ [worker_a, worker_b]
|
166
|
+
subject.clear_workers
|
167
|
+
subject.workers.should =~ []
|
168
|
+
end
|
169
|
+
|
120
170
|
end
|
data/spec/runner_spec.rb
CHANGED
@@ -60,7 +60,7 @@ describe SBM::Runner do
|
|
60
60
|
context 'with a runner' do
|
61
61
|
|
62
62
|
it 'should let you validate the command' do
|
63
|
-
['status', 'start-batch', 'complete-batch', 'wait-for'].each do |command|
|
63
|
+
['status', 'start-batch', 'complete-batch', 'wait-for', 'clear-batch', 'clear-batches', 'clear-workers'].each do |command|
|
64
64
|
instance = described_class.new [command], output, error
|
65
65
|
dont_allow(instance).exit.with_any_args
|
66
66
|
instance.validate_command!
|
@@ -158,6 +158,36 @@ describe SBM::Runner do
|
|
158
158
|
|
159
159
|
end
|
160
160
|
|
161
|
+
context 'clearing a batch' do
|
162
|
+
|
163
|
+
it 'should be an error without a batch name' do
|
164
|
+
subject.args.should == []
|
165
|
+
mock(subject).exit 1
|
166
|
+
subject.clear_batch
|
167
|
+
end
|
168
|
+
|
169
|
+
it 'should work with the coordinator' do
|
170
|
+
subject.args.replace %w(xyz)
|
171
|
+
mock(subject.coordinator).clear SBM::Coordinator::Batch.new('xyz')
|
172
|
+
dont_allow(subject).exit
|
173
|
+
subject.clear_batch
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
it 'should let you clear all batches' do
|
178
|
+
subject.args.replace []
|
179
|
+
mock(subject.coordinator).clear_batches
|
180
|
+
dont_allow(subject).exit
|
181
|
+
subject.clear_batches
|
182
|
+
end
|
183
|
+
|
184
|
+
it 'should let you clear all workers' do
|
185
|
+
subject.args.replace []
|
186
|
+
mock(subject.coordinator).clear_workers
|
187
|
+
dont_allow(subject).exit
|
188
|
+
subject.clear_workers
|
189
|
+
end
|
190
|
+
|
161
191
|
end
|
162
192
|
|
163
193
|
end
|