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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
ffd970d9
Commit
ffd970d9
authored
Mar 03, 2017
by
Stan Hu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make SidekiqStatus able to count number of jobs completed/running
parent
312137c6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
6 deletions
+55
-6
lib/gitlab/sidekiq_status.rb
lib/gitlab/sidekiq_status.rb
+29
-6
spec/lib/gitlab/sidekiq_status_spec.rb
spec/lib/gitlab/sidekiq_status_spec.rb
+26
-0
No files found.
lib/gitlab/sidekiq_status.rb
View file @
ffd970d9
...
...
@@ -44,19 +44,42 @@ module Gitlab
# Returns true if all the given job have been completed.
#
# jids - The Sidekiq job IDs to check.
# j
ob_
ids - The Sidekiq job IDs to check.
#
# Returns true or false.
def
self
.
all_completed?
(
jids
)
keys
=
jids
.
map
{
|
jid
|
key_for
(
jid
)
}
def
self
.
all_completed?
(
job_ids
)
self
.
num_running
(
job_ids
).
zero?
end
# Returns the number of jobs that are running.
#
# job_ids - The Sidekiq job IDs to check.
def
self
.
num_running
(
job_ids
)
responses
=
self
.
job_status
(
job_ids
)
responses
=
Sidekiq
.
redis
do
|
redis
|
responses
.
select
(
&
:present?
).
count
end
# Returns the number of jobs that have completed.
#
# job_ids - The Sidekiq job IDs to check.
def
self
.
num_completed
(
job_ids
)
job_ids
.
size
-
self
.
num_running
(
job_ids
)
end
# Returns the job status for each of the given job IDs.
#
# job_ids - The Sidekiq job IDs to check.
#
# Returns an array of true or false indicating job completion.
def
self
.
job_status
(
job_ids
)
keys
=
job_ids
.
map
{
|
jid
|
key_for
(
jid
)
}
Sidekiq
.
redis
do
|
redis
|
redis
.
pipelined
do
keys
.
each
{
|
key
|
redis
.
exists
(
key
)
}
end
end
responses
.
all?
{
|
value
|
!
value
}
end
def
self
.
key_for
(
jid
)
...
...
spec/lib/gitlab/sidekiq_status_spec.rb
View file @
ffd970d9
...
...
@@ -39,6 +39,32 @@ describe Gitlab::SidekiqStatus do
end
end
describe
'.num_running'
,
:redis
do
it
'returns 0 if all jobs have been completed'
do
expect
(
described_class
.
num_running
(
%w(123)
)).
to
eq
(
0
)
end
it
'returns 2 if two jobs are still running'
do
described_class
.
set
(
'123'
)
described_class
.
set
(
'456'
)
expect
(
described_class
.
num_running
(
%w(123 456 789)
)).
to
eq
(
2
)
end
end
describe
'.num_completed'
,
:redis
do
it
'returns 1 if all jobs have been completed'
do
expect
(
described_class
.
num_completed
(
%w(123)
)).
to
eq
(
1
)
end
it
'returns 1 if a job has not yet been completed'
do
described_class
.
set
(
'123'
)
described_class
.
set
(
'456'
)
expect
(
described_class
.
num_completed
(
%w(123 456 789)
)).
to
eq
(
1
)
end
end
describe
'.key_for'
do
it
'returns the key for a job ID'
do
key
=
described_class
.
key_for
(
'123'
)
...
...
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