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
Tatuya Kamada
gitlab-ce
Commits
0ba385b3
Commit
0ba385b3
authored
Feb 07, 2017
by
Tomasz Maczukin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add exclusive lease for stuck_ci_builds_worker
parent
a4e996d7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
3 deletions
+27
-3
app/workers/stuck_ci_builds_worker.rb
app/workers/stuck_ci_builds_worker.rb
+11
-2
spec/workers/stuck_ci_builds_worker_spec.rb
spec/workers/stuck_ci_builds_worker_spec.rb
+16
-1
No files found.
app/workers/stuck_ci_builds_worker.rb
View file @
0ba385b3
...
@@ -7,7 +7,9 @@ class StuckCiBuildsWorker
...
@@ -7,7 +7,9 @@ class StuckCiBuildsWorker
BUILD_PENDING_STUCK_TIMEOUT
=
1
.
hour
BUILD_PENDING_STUCK_TIMEOUT
=
1
.
hour
def
perform
def
perform
Rails
.
logger
.
info
'Cleaning stuck builds'
return
unless
try_obtain_lease
Rails
.
logger
.
info
"
#{
self
.
class
}
: Cleaning stuck builds"
drop
:running
,
BUILD_RUNNING_OUTDATED_TIMEOUT
drop
:running
,
BUILD_RUNNING_OUTDATED_TIMEOUT
drop
:pending
,
BUILD_PENDING_OUTDATED_TIMEOUT
drop
:pending
,
BUILD_PENDING_OUTDATED_TIMEOUT
...
@@ -16,6 +18,13 @@ class StuckCiBuildsWorker
...
@@ -16,6 +18,13 @@ class StuckCiBuildsWorker
private
private
def
try_obtain_lease
Gitlab
::
ExclusiveLease
.
new
(
'stuck_ci_builds_worker_lease'
,
timeout:
30
.
minutes
).
try_obtain
end
def
drop
(
status
,
timeout
)
def
drop
(
status
,
timeout
)
search
(
status
,
timeout
)
do
|
build
|
search
(
status
,
timeout
)
do
|
build
|
drop_build
:outdated
,
build
,
status
,
timeout
drop_build
:outdated
,
build
,
status
,
timeout
...
@@ -37,7 +46,7 @@ class StuckCiBuildsWorker
...
@@ -37,7 +46,7 @@ class StuckCiBuildsWorker
end
end
def
drop_build
(
type
,
build
,
status
,
timeout
)
def
drop_build
(
type
,
build
,
status
,
timeout
)
Rails
.
logger
.
info
"
#{
self
.
class
}
: Dropping
#{
type
.
to_s
}
build
#{
build
.
id
}
for runner
#{
build
.
runner_id
}
(status:
#{
status
}
, timeout:
#{
timeout
}
)"
Rails
.
logger
.
info
"
#{
self
.
class
}
: Dropping
#{
type
}
build
#{
build
.
id
}
for runner
#{
build
.
runner_id
}
(status:
#{
status
}
, timeout:
#{
timeout
}
)"
build
.
drop
build
.
drop
end
end
end
end
spec/workers/stuck_ci_builds_worker_spec.rb
View file @
0ba385b3
...
@@ -10,7 +10,10 @@ describe StuckCiBuildsWorker do
...
@@ -10,7 +10,10 @@ describe StuckCiBuildsWorker do
build
.
status
build
.
status
end
end
before
{
build
.
update!
(
status:
status
,
updated_at:
updated_at
)
}
before
do
build
.
update!
(
status:
status
,
updated_at:
updated_at
)
allow_any_instance_of
(
Gitlab
::
ExclusiveLease
).
to
receive
(
:try_obtain
).
and_return
(
true
)
end
shared_examples
'build is dropped'
do
shared_examples
'build is dropped'
do
it
'changes status'
do
it
'changes status'
do
...
@@ -96,4 +99,16 @@ describe StuckCiBuildsWorker do
...
@@ -96,4 +99,16 @@ describe StuckCiBuildsWorker do
worker
.
perform
worker
.
perform
end
end
end
end
describe
'exclusive lease'
do
let
(
:status
)
{
'running'
}
let
(
:updated_at
)
{
2
.
days
.
ago
}
it
'is guard by exclusive lease'
do
worker
.
perform
allow_any_instance_of
(
Gitlab
::
ExclusiveLease
).
to
receive
(
:try_obtain
).
and_return
(
false
)
expect
(
worker
).
not_to
receive
(
:drop
)
worker
.
perform
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