summaryrefslogtreecommitdiff
path: root/app/helpers/sidekiq_helper.rb
blob: 07d83b8d850de30d4bb4df403c29f7c989a703f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# frozen_string_literal: true

module SidekiqHelper
  SIDEKIQ_PS_REGEXP = %r{\A
    (?<pid>\d+)\s+
    (?<cpu>[\d\.,]+)\s+
    (?<mem>[\d\.,]+)\s+
    (?<state>[DIEKNRSTVWXZLpsl\+<>/\d]+)\s+
    (?<start>.+?)\s+
    (?<command>(?:ruby\d+:\s+)?sidekiq.*\].*)
    \z}x.freeze

  def parse_sidekiq_ps(line)
    match = line.strip.match(SIDEKIQ_PS_REGEXP)
    match ? match[1..6] : Array.new(6, '?')
  end
end