daily pastebin goal
94%
SHARE
TWEET

Untitled

a guest Sep 14th, 2018 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. consumer_ids = [0, 1, 2]
  2. topics_to_partitions = { 'iq_delivery_receipt' => 6, 'iq_delivery_recommendation' => 4 }
  3.  
  4. def assign(members:, topics_to_partitions:)
  5.   group_assignment = {}
  6.  
  7.   topics_to_partitions.each do |topic, num_partitions|
  8.     partitions = *(0..num_partitions - 1)
  9.    
  10.     partitions_per_member = partitions.group_by {|partition_id|
  11.       partition_id % members.count
  12.     }.values
  13.  
  14.     members.zip(partitions_per_member).each do |member_id, member_partitions|
  15.       unless member_partitions.nil?
  16.         group_assignment[member_id].assign(topic, member_partitions)
  17.       end
  18.     end
  19.   end
  20.  
  21.   group_assignment
  22. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top