Class: SnapCI::ParallelTests::Grouper
- Inherits:
-
Object
- Object
- SnapCI::ParallelTests::Grouper
- Defined in:
- lib/snap_ci/parallel_tests/grouper.rb
Class Method Summary collapse
- .distribute_by_chunk(things, total_workers, current_worker_index) ⇒ Object
- .distribute_by_round_robin(things, total_workers, current_worker_index) ⇒ Object
- .group_by_filename(things) ⇒ Object
- .group_by_filesize(things) ⇒ Object
Class Method Details
.distribute_by_chunk(things, total_workers, current_worker_index) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/snap_ci/parallel_tests/grouper.rb', line 27 def distribute_by_chunk(things, total_workers, current_worker_index) thing_count = things.count specs_per_worker = (thing_count.to_f/total_workers).ceil things.each_slice(specs_per_worker).to_a[current_worker_index-1] || [] end |
.distribute_by_round_robin(things, total_workers, current_worker_index) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/snap_ci/parallel_tests/grouper.rb', line 13 def distribute_by_round_robin(things, total_workers, current_worker_index) result = [] # pick up things on a round-robin basis to distribute them evenly index = current_worker_index - 1 while index <= things.count do result << things[index] index += total_workers end result.compact! result end |
.group_by_filename(things) ⇒ Object
5 6 7 |
# File 'lib/snap_ci/parallel_tests/grouper.rb', line 5 def group_by_filename(things) things.sort end |
.group_by_filesize(things) ⇒ Object
9 10 11 |
# File 'lib/snap_ci/parallel_tests/grouper.rb', line 9 def group_by_filesize(things) things.sort { |a, b| File.size(a) <=> File.size(b) } end |