sshkit-chunky-runner 0.1.0 → 0.2.0
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 965046b809835e032c4fe94190e8284c2aadec29
|
4
|
+
data.tar.gz: 7402accf87a241ff2b7a7d8280090121320491e1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bbcb5db6c6971a21b558eac9639c12c2f5ba57a1790f5733257bad808183eaf06b3994d140bc54cceb971cf0d217bfb2c80a780457171caf7f80fc5a0454a488
|
7
|
+
data.tar.gz: 5a194a3d9fd24f4b04b27af49ae5356cab79c5c9f594751eb69f487a699f27aecfaa006ae14489c9ee6fa1331c72095ca075101d74142f25cd3150dd3f16c26d
|
@@ -1,13 +1,34 @@
|
|
1
1
|
module SSHKit
|
2
2
|
module Chunky
|
3
3
|
module Runner
|
4
|
-
class Chunks < SSHKit::Runner::
|
4
|
+
class Chunks < SSHKit::Runner::Sequential
|
5
5
|
attr_writer :chunks_count
|
6
6
|
|
7
|
+
def execute
|
8
|
+
each_chunk(hosts).map do |group_hosts|
|
9
|
+
SSHKit::Runner::Parallel.new(group_hosts, &block).execute
|
10
|
+
sleep wait_interval
|
11
|
+
end.flatten
|
12
|
+
end
|
13
|
+
|
7
14
|
private
|
8
15
|
|
9
|
-
def
|
10
|
-
|
16
|
+
def each_chunk(array)
|
17
|
+
return array.map { |item| [item] } if array.size <= chunks_count
|
18
|
+
|
19
|
+
division = array.size.div chunks_count
|
20
|
+
modulo = array.size % chunks_count
|
21
|
+
|
22
|
+
groups = []
|
23
|
+
start = 0
|
24
|
+
|
25
|
+
chunks_count.times do |index|
|
26
|
+
length = division + (modulo > 0 && modulo > index ? 1 : 0)
|
27
|
+
groups << array.slice(start, length)
|
28
|
+
start += length
|
29
|
+
end
|
30
|
+
|
31
|
+
groups
|
11
32
|
end
|
12
33
|
|
13
34
|
def chunks_count
|
@@ -1,36 +1,70 @@
|
|
1
1
|
require 'sshkit/chunky/runner/chunks'
|
2
2
|
|
3
3
|
describe SSHKit::Chunky::Runner::Chunks do
|
4
|
-
describe '#
|
5
|
-
let(:options) { { count:
|
4
|
+
describe '#each_chunk' do
|
5
|
+
let(:options) { { count: 4, sleep: 0 } }
|
6
6
|
let(:block_to_run) { ->(host) { execute "echo #{Time.now.to_i}" } }
|
7
7
|
let(:runner) do
|
8
8
|
SSHKit::Chunky::Runner::Chunks.new(hosts, options, &block_to_run)
|
9
9
|
end
|
10
10
|
|
11
|
-
subject(:
|
11
|
+
subject(:each_chunk) { runner.send(:each_chunk, hosts) }
|
12
12
|
|
13
13
|
context 'with one host' do
|
14
14
|
let(:hosts) { ['example.com'] }
|
15
15
|
|
16
|
-
it 'returns
|
17
|
-
expect(
|
16
|
+
it 'returns 1 group' do
|
17
|
+
expect(each_chunk.size).to eq 1
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'returns 1 item in first group' do
|
21
|
+
expect(each_chunk.first.size).to eq 1
|
18
22
|
end
|
19
23
|
end
|
20
24
|
|
21
|
-
context 'with
|
22
|
-
let(:hosts) { ['example.com'] *
|
25
|
+
context 'with 3 hosts' do
|
26
|
+
let(:hosts) { ['example.com'] * 3 }
|
27
|
+
|
28
|
+
it 'returns 3 groups' do
|
29
|
+
expect(each_chunk.size).to eq 3
|
30
|
+
end
|
23
31
|
|
24
|
-
it 'returns
|
25
|
-
expect(
|
32
|
+
it 'returns 1 item in each group' do
|
33
|
+
expect(each_chunk[0].size).to eq 1
|
34
|
+
expect(each_chunk[1].size).to eq 1
|
35
|
+
expect(each_chunk[2].size).to eq 1
|
26
36
|
end
|
27
37
|
end
|
28
38
|
|
29
|
-
context 'with
|
30
|
-
let(:hosts) { ['example.com'] *
|
39
|
+
context 'with 8 hosts' do
|
40
|
+
let(:hosts) { ['example.com'] * 8 }
|
41
|
+
|
42
|
+
it 'returns 4 groups' do
|
43
|
+
expect(each_chunk.size).to eq 4
|
44
|
+
end
|
45
|
+
it 'returns 2 items in each group' do
|
46
|
+
expect(each_chunk[0].size).to eq 2
|
47
|
+
expect(each_chunk[1].size).to eq 2
|
48
|
+
expect(each_chunk[2].size).to eq 2
|
49
|
+
expect(each_chunk[3].size).to eq 2
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context 'with 9 hosts' do
|
54
|
+
let(:hosts) { ['example.com'] * 9 }
|
55
|
+
|
56
|
+
it 'returns 4 groups' do
|
57
|
+
expect(each_chunk.size).to eq 4
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'returns 3 items in first group' do
|
61
|
+
expect(each_chunk[0].size).to eq 3
|
62
|
+
end
|
31
63
|
|
32
|
-
it 'returns
|
33
|
-
expect(
|
64
|
+
it 'returns 2 items in other groups' do
|
65
|
+
expect(each_chunk[1].size).to eq 2
|
66
|
+
expect(each_chunk[2].size).to eq 2
|
67
|
+
expect(each_chunk[3].size).to eq 2
|
34
68
|
end
|
35
69
|
end
|
36
70
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sshkit-chunky-runner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tomas Brazys
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-12-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|