Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Jérome Perrin
gitlab-ce
Commits
d027ed71
Commit
d027ed71
authored
Sep 08, 2016
by
Pascal Betz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reformat Regexp
Fix show template (missing tr) Separate exercise/verify
parent
de6a44fa
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
3 deletions
+18
-3
app/helpers/sidekiq_helper.rb
app/helpers/sidekiq_helper.rb
+9
-0
app/views/admin/background_jobs/show.html.haml
app/views/admin/background_jobs/show.html.haml
+4
-3
spec/helpers/sidekiq_helper_spec.rb
spec/helpers/sidekiq_helper_spec.rb
+5
-0
No files found.
app/helpers/sidekiq_helper.rb
View file @
d027ed71
module
SidekiqHelper
module
SidekiqHelper
SIDEKIQ_PS_REGEXP
=
/\A([^\s]+)\s+([^\s]+)\s+([^\s]+)\s+([^\s]+)\s+(.+)\s+(sidekiq.*\])\s+\z/
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
)
def
parse_sidekiq_ps
(
line
)
match
=
line
.
match
(
SIDEKIQ_PS_REGEXP
)
match
=
line
.
match
(
SIDEKIQ_PS_REGEXP
)
if
match
if
match
...
...
app/views/admin/background_jobs/show.html.haml
View file @
d027ed71
...
@@ -28,6 +28,7 @@
...
@@ -28,6 +28,7 @@
%th
COMMAND
%th
COMMAND
%tbody
%tbody
-
@sidekiq_processes
.
each
do
|
process
|
-
@sidekiq_processes
.
each
do
|
process
|
%tr
%td
=
gitlab_config
.
user
%td
=
gitlab_config
.
user
-
parse_sidekiq_ps
(
process
).
each
do
|
value
|
-
parse_sidekiq_ps
(
process
).
each
do
|
value
|
%td
=
value
%td
=
value
...
...
spec/helpers/sidekiq_helper_spec.rb
View file @
d027ed71
...
@@ -5,30 +5,35 @@ describe SidekiqHelper do
...
@@ -5,30 +5,35 @@ describe SidekiqHelper do
it
'parses line with time'
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] '
line
=
'55137 10,0 2,1 S+ 2:30pm sidekiq 4.1.4 gitlab [0 of 25 busy] '
parts
=
helper
.
parse_sidekiq_ps
(
line
)
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]'
])
expect
(
parts
).
to
eq
([
'55137'
,
'10,0'
,
'2,1'
,
'S+'
,
'2:30pm'
,
'sidekiq 4.1.4 gitlab [0 of 25 busy]'
])
end
end
it
'parses line with date'
do
it
'parses line with date'
do
line
=
'55137 10,0 2,1 S+ Aug 4 sidekiq 4.1.4 gitlab [0 of 25 busy] '
line
=
'55137 10,0 2,1 S+ Aug 4 sidekiq 4.1.4 gitlab [0 of 25 busy] '
parts
=
helper
.
parse_sidekiq_ps
(
line
)
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]'
])
expect
(
parts
).
to
eq
([
'55137'
,
'10,0'
,
'2,1'
,
'S+'
,
'Aug 4'
,
'sidekiq 4.1.4 gitlab [0 of 25 busy]'
])
end
end
it
'parses line with two digit date'
do
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] '
line
=
'55137 10,0 2,1 S+ Aug 04 sidekiq 4.1.4 gitlab [0 of 25 busy] '
parts
=
helper
.
parse_sidekiq_ps
(
line
)
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]'
])
expect
(
parts
).
to
eq
([
'55137'
,
'10,0'
,
'2,1'
,
'S+'
,
'Aug 04'
,
'sidekiq 4.1.4 gitlab [0 of 25 busy]'
])
end
end
it
'parses line with dot as float separator'
do
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] '
line
=
'55137 10.0 2.1 S+ 2:30pm sidekiq 4.1.4 gitlab [0 of 25 busy] '
parts
=
helper
.
parse_sidekiq_ps
(
line
)
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]'
])
expect
(
parts
).
to
eq
([
'55137'
,
'10.0'
,
'2.1'
,
'S+'
,
'2:30pm'
,
'sidekiq 4.1.4 gitlab [0 of 25 busy]'
])
end
end
it
'does fail gracefully on line not matching the format'
do
it
'does fail gracefully on line not matching the format'
do
line
=
'55137 10.0 2.1 S+ 2:30pm something'
line
=
'55137 10.0 2.1 S+ 2:30pm something'
parts
=
helper
.
parse_sidekiq_ps
(
line
)
parts
=
helper
.
parse_sidekiq_ps
(
line
)
expect
(
parts
).
to
eq
([
'?'
,
'?'
,
'?'
,
'?'
,
'?'
,
'?'
])
expect
(
parts
).
to
eq
([
'?'
,
'?'
,
'?'
,
'?'
,
'?'
,
'?'
])
end
end
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment