Commit 1112b5a2 authored by Pascal Betz's avatar Pascal Betz

Move parsing of sidekiq ps into helper

parent 80e575af
module SidekiqHelper
SIDEKIQ_PS_REGEXP = /\A([^\s]+)\s+([^\s]+)\s+([^\s]+)\s+([^\s]+)\s+(.+)\s+(sidekiq.*\])\s+\z/
def parse_sidekiq_ps(line)
match = line.match(SIDEKIQ_PS_REGEXP)
if match
match[1..6]
else
%w{? ? ? ? ? ?}
end
end
end
...@@ -28,14 +28,9 @@ ...@@ -28,14 +28,9 @@
%th COMMAND %th COMMAND
%tbody %tbody
- @sidekiq_processes.each do |process| - @sidekiq_processes.each do |process|
- next unless process.match(/(sidekiq \d+\.\d+\.\d+.+$)/) %td= gitlab_config.user
- data = process.strip.split(' ') -parse_sidekiq_ps(process).each do |value|
%tr %td= value
%td= gitlab_config.user
- 5.times do
%td= data.shift
%td= data.join(' ')
.clearfix .clearfix
%p %p
%i.fa.fa-exclamation-circle %i.fa.fa-exclamation-circle
......
require 'spec_helper'
describe SidekiqHelper do
describe 'parse_sidekiq_ps' do
it 'parses line with time' do
line = '55137 10,0 2,1 S+ 2:30pm sidekiq 4.1.4 gitlab [0 of 25 busy] '
parts = helper.parse_sidekiq_ps(line)
expect(parts).to eq(['55137', '10,0', '2,1', 'S+', '2:30pm', 'sidekiq 4.1.4 gitlab [0 of 25 busy]'])
end
it 'parses line with date' do
line = '55137 10,0 2,1 S+ Aug 4 sidekiq 4.1.4 gitlab [0 of 25 busy] '
parts = helper.parse_sidekiq_ps(line)
expect(parts).to eq(['55137', '10,0', '2,1', 'S+', 'Aug 4', 'sidekiq 4.1.4 gitlab [0 of 25 busy]'])
end
it 'parses line with two digit date' do
line = '55137 10,0 2,1 S+ Aug 04 sidekiq 4.1.4 gitlab [0 of 25 busy] '
parts = helper.parse_sidekiq_ps(line)
expect(parts).to eq(['55137', '10,0', '2,1', 'S+', 'Aug 04', 'sidekiq 4.1.4 gitlab [0 of 25 busy]'])
end
it 'parses line with dot as float separator' do
line = '55137 10.0 2.1 S+ 2:30pm sidekiq 4.1.4 gitlab [0 of 25 busy] '
parts = helper.parse_sidekiq_ps(line)
expect(parts).to eq(['55137', '10.0', '2.1', 'S+', '2:30pm', 'sidekiq 4.1.4 gitlab [0 of 25 busy]'])
end
it 'does fail gracefully on line not matching the format' do
line = '55137 10.0 2.1 S+ 2:30pm something'
parts = helper.parse_sidekiq_ps(line)
expect(parts).to eq(['?', '?', '?', '?', '?', '?'])
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment