lib/sidekiq/web/helpers.rb in sidekiq-7.0.0.beta1 vs lib/sidekiq/web/helpers.rb in sidekiq-7.0.0

- old
+ new

@@ -146,28 +146,18 @@ def processes @processes ||= Sidekiq::ProcessSet.new end - # Sorts processes by hostname following the natural sort order so that - # 'worker.1' < 'worker.2' < 'worker.10' < 'worker.20' - # '2.1.1.1' < '192.168.0.2' < '192.168.0.10' + # Sorts processes by hostname following the natural sort order def sorted_processes @sorted_processes ||= begin return processes unless processes.all? { |p| p["hostname"] } - split_characters = /[._-]+/ - - padding = processes.flat_map { |p| p["hostname"].split(split_characters) }.map(&:size).max - processes.to_a.sort_by do |process| - process["hostname"].split(split_characters).map do |substring| - # Left-pad the substring with '0' if it starts with a number or 'a' - # otherwise, so that '25' < 192' < 'a' ('025' < '192' < 'aaa') - padding_char = substring[0].match?(/\d/) ? "0" : "a" - - substring.rjust(padding, padding_char) - end + # Kudos to `shurikk` on StackOverflow + # https://stackoverflow.com/a/15170063/575547 + process["hostname"].split(/(\d+)/).map { |a| /\d+/.match?(a) ? a.to_i : a } end end end def stats