summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPascal Betz <pascal.betz@gmail.com>2016-09-08 15:30:16 +0200
committerPascal Betz <pascal.betz@gmail.com>2016-09-08 15:46:22 +0200
commitd027ed719dfdfabb687985ec6d4c6301953102cc (patch)
treee02d4b7e221fd7c37d886c95fea236138b3be66b
parentde6a44fae6273c44ef27ff55d13799efc9756acd (diff)
downloadgitlab-ce-d027ed719dfdfabb687985ec6d4c6301953102cc.tar.gz
Reformat Regexp
Fix show template (missing tr) Separate exercise/verify
-rw-r--r--app/helpers/sidekiq_helper.rb9
-rw-r--r--app/views/admin/background_jobs/show.html.haml7
-rw-r--r--spec/helpers/sidekiq_helper_spec.rb5
3 files changed, 18 insertions, 3 deletions
diff --git a/app/helpers/sidekiq_helper.rb b/app/helpers/sidekiq_helper.rb
index 82ab26408df..37650ca642b 100644
--- a/app/helpers/sidekiq_helper.rb
+++ b/app/helpers/sidekiq_helper.rb
@@ -1,6 +1,15 @@
module SidekiqHelper
SIDEKIQ_PS_REGEXP = /\A([^\s]+)\s+([^\s]+)\s+([^\s]+)\s+([^\s]+)\s+(.+)\s+(sidekiq.*\])\s+\z/
+ SIDEKIQ_PS_REGEXP = /\A
+ (?<pid>\d+)\s+
+ (?<cpu>[\d\.,]+)\s+
+ (?<mem>[\d\.,]+)\s+
+ (?<state>[DRSTWXZNLsl\+<]+)\s+
+ (?<start>.+)\s+
+ (?<command>sidekiq.*\])\s+
+ \z/x
+
def parse_sidekiq_ps(line)
match = line.match(SIDEKIQ_PS_REGEXP)
if match
diff --git a/app/views/admin/background_jobs/show.html.haml b/app/views/admin/background_jobs/show.html.haml
index 058919635da..05855db963a 100644
--- a/app/views/admin/background_jobs/show.html.haml
+++ b/app/views/admin/background_jobs/show.html.haml
@@ -28,9 +28,10 @@
%th COMMAND
%tbody
- @sidekiq_processes.each do |process|
- %td= gitlab_config.user
- - parse_sidekiq_ps(process).each do |value|
- %td= value
+ %tr
+ %td= gitlab_config.user
+ - parse_sidekiq_ps(process).each do |value|
+ %td= value
.clearfix
%p
%i.fa.fa-exclamation-circle
diff --git a/spec/helpers/sidekiq_helper_spec.rb b/spec/helpers/sidekiq_helper_spec.rb
index 2eb1c816bc5..d60839b78ec 100644
--- a/spec/helpers/sidekiq_helper_spec.rb
+++ b/spec/helpers/sidekiq_helper_spec.rb
@@ -5,30 +5,35 @@ describe SidekiqHelper 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