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
Boxiang Sun
gitlab-ce
Commits
b78954c1
Commit
b78954c1
authored
Oct 13, 2017
by
Oswaldo Ferreira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify check for running job on Redis
parent
9ab02540
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
22 additions
and
3 deletions
+22
-3
app/models/merge_request.rb
app/models/merge_request.rb
+1
-1
lib/gitlab/sidekiq_status.rb
lib/gitlab/sidekiq_status.rb
+7
-0
spec/lib/gitlab/sidekiq_status_spec.rb
spec/lib/gitlab/sidekiq_status_spec.rb
+12
-0
spec/models/merge_request_spec.rb
spec/models/merge_request_spec.rb
+2
-2
No files found.
app/models/merge_request.rb
View file @
b78954c1
...
@@ -396,7 +396,7 @@ class MergeRequest < ActiveRecord::Base
...
@@ -396,7 +396,7 @@ class MergeRequest < ActiveRecord::Base
end
end
def
merge_ongoing?
def
merge_ongoing?
!!
merge_jid
&&
!
merged?
&&
Gitlab
::
SidekiqStatus
.
num_running
([
merge_jid
])
>
0
!!
merge_jid
&&
!
merged?
&&
Gitlab
::
SidekiqStatus
.
running?
(
merge_jid
)
end
end
def
closed_without_fork?
def
closed_without_fork?
...
...
lib/gitlab/sidekiq_status.rb
View file @
b78954c1
...
@@ -51,6 +51,13 @@ module Gitlab
...
@@ -51,6 +51,13 @@ module Gitlab
self
.
num_running
(
job_ids
).
zero?
self
.
num_running
(
job_ids
).
zero?
end
end
# Returns true if the given job is running
#
# job_id - The Sidekiq job ID to check.
def
self
.
running?
(
job_id
)
num_running
([
job_id
])
>
0
end
# Returns the number of jobs that are running.
# Returns the number of jobs that are running.
#
#
# job_ids - The Sidekiq job IDs to check.
# job_ids - The Sidekiq job IDs to check.
...
...
spec/lib/gitlab/sidekiq_status_spec.rb
View file @
b78954c1
...
@@ -39,6 +39,18 @@ describe Gitlab::SidekiqStatus do
...
@@ -39,6 +39,18 @@ describe Gitlab::SidekiqStatus do
end
end
end
end
describe
'.running?'
,
:clean_gitlab_redis_shared_state
do
it
'returns true if job is running'
do
described_class
.
set
(
'123'
)
expect
(
described_class
.
running?
(
'123'
)).
to
be
(
true
)
end
it
'returns false if job is not found'
do
expect
(
described_class
.
running?
(
'123'
)).
to
be
(
false
)
end
end
describe
'.num_running'
,
:clean_gitlab_redis_shared_state
do
describe
'.num_running'
,
:clean_gitlab_redis_shared_state
do
it
'returns 0 if all jobs have been completed'
do
it
'returns 0 if all jobs have been completed'
do
expect
(
described_class
.
num_running
(
%w(123)
)).
to
eq
(
0
)
expect
(
described_class
.
num_running
(
%w(123)
)).
to
eq
(
0
)
...
...
spec/models/merge_request_spec.rb
View file @
b78954c1
...
@@ -1462,7 +1462,7 @@ describe MergeRequest do
...
@@ -1462,7 +1462,7 @@ describe MergeRequest do
describe
'#merge_ongoing?'
do
describe
'#merge_ongoing?'
do
it
'returns true when merge_id, MR is not merged and it has no running job'
do
it
'returns true when merge_id, MR is not merged and it has no running job'
do
merge_request
=
build_stubbed
(
:merge_request
,
state: :open
,
merge_jid:
'foo'
)
merge_request
=
build_stubbed
(
:merge_request
,
state: :open
,
merge_jid:
'foo'
)
allow
(
Gitlab
::
SidekiqStatus
).
to
receive
(
:
num_running
).
with
([
'foo'
])
{
1
}
allow
(
Gitlab
::
SidekiqStatus
).
to
receive
(
:
running?
).
with
(
'foo'
)
{
true
}
expect
(
merge_request
.
merge_ongoing?
).
to
be
(
true
)
expect
(
merge_request
.
merge_ongoing?
).
to
be
(
true
)
end
end
...
@@ -1481,7 +1481,7 @@ describe MergeRequest do
...
@@ -1481,7 +1481,7 @@ describe MergeRequest do
it
'returns false if there is no merge job running'
do
it
'returns false if there is no merge job running'
do
merge_request
=
build_stubbed
(
:merge_request
,
state: :open
,
merge_jid:
'foo'
)
merge_request
=
build_stubbed
(
:merge_request
,
state: :open
,
merge_jid:
'foo'
)
allow
(
Gitlab
::
SidekiqStatus
).
to
receive
(
:
num_running
).
with
([
'foo'
])
{
0
}
allow
(
Gitlab
::
SidekiqStatus
).
to
receive
(
:
running?
).
with
(
'foo'
)
{
false
}
expect
(
merge_request
.
merge_ongoing?
).
to
be
(
false
)
expect
(
merge_request
.
merge_ongoing?
).
to
be
(
false
)
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