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
a02fe251
Commit
a02fe251
authored
Mar 14, 2016
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow project housekeeping only once an hour
parent
37ba5a12
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
56 additions
and
2 deletions
+56
-2
app/controllers/projects_controller.rb
app/controllers/projects_controller.rb
+2
-2
app/services/projects/housekeeping_service.rb
app/services/projects/housekeeping_service.rb
+14
-0
spec/services/projects/housekeeping_service_spec.rb
spec/services/projects/housekeeping_service_spec.rb
+40
-0
No files found.
app/controllers/projects_controller.rb
View file @
a02fe251
...
@@ -170,10 +170,10 @@ class ProjectsController < ApplicationController
...
@@ -170,10 +170,10 @@ class ProjectsController < ApplicationController
end
end
def
housekeeping
def
housekeeping
::
Projects
::
HousekeepingService
.
new
(
@project
).
execute
message
=
::
Projects
::
HousekeepingService
.
new
(
@project
).
execute
respond_to
do
|
format
|
respond_to
do
|
format
|
flash
[
:notice
]
=
"Housekeeping successfully started."
flash
[
:notice
]
=
message
format
.
html
{
redirect_to
project_path
(
@project
)
}
format
.
html
{
redirect_to
project_path
(
@project
)
}
end
end
end
end
...
...
app/services/projects/housekeeping_service.rb
View file @
a02fe251
...
@@ -9,12 +9,26 @@ module Projects
...
@@ -9,12 +9,26 @@ module Projects
class
HousekeepingService
<
BaseService
class
HousekeepingService
<
BaseService
include
Gitlab
::
ShellAdapter
include
Gitlab
::
ShellAdapter
LEASE_TIMEOUT
=
3600
def
initialize
(
project
)
def
initialize
(
project
)
@project
=
project
@project
=
project
end
end
def
execute
def
execute
if
!
try_obtain_lease
return
"Housekeeping was already triggered in the past
#{
LEASE_TIMEOUT
/
60
}
minutes"
end
GitlabShellWorker
.
perform_async
(
:gc
,
@project
.
path_with_namespace
)
GitlabShellWorker
.
perform_async
(
:gc
,
@project
.
path_with_namespace
)
return
"Housekeeping successfully started"
end
private
def
try_obtain_lease
lease
=
::
Gitlab
::
ExclusiveLease
.
new
(
"project_housekeeping:
#{
@project
.
id
}
"
,
timeout:
LEASE_TIMEOUT
)
lease
.
try_obtain
end
end
end
end
end
end
spec/services/projects/housekeeping_service_spec.rb
0 → 100644
View file @
a02fe251
require
'spec_helper'
describe
Projects
::
HousekeepingService
do
subject
{
Projects
::
HousekeepingService
.
new
(
project
)
}
let
(
:project
)
{
create
:project
}
describe
:execute
do
before
do
project
.
pushes_since_gc
=
3
project
.
save!
end
it
'enqueues a sidekiq job'
do
expect
(
subject
).
to
receive
(
:try_obtain_lease
).
and_return
(
true
)
expect
(
GitlabShellWorker
).
to
receive
(
:perform_async
).
with
(
:gc
,
project
.
path_with_namespace
)
expect
(
subject
.
execute
).
to
include
(
'successfully started'
)
expect
(
project
.
pushes_since_gc
).
to
eq
(
0
)
end
it
'does not enqueue a job when no lease can be obtained'
do
expect
(
subject
).
to
receive
(
:try_obtain_lease
).
and_return
(
false
)
expect
(
GitlabShellWorker
).
not_to
receive
(
:perform_async
)
expect
(
subject
.
execute
).
to
include
(
'already triggered'
)
expect
(
project
.
pushes_since_gc
).
to
eq
(
3
)
end
end
describe
:needed?
do
it
'when the count is low enough'
do
expect
(
subject
.
needed?
).
to
eq
(
false
)
end
it
'when the count is high enough'
do
allow
(
project
).
to
receive
(
:pushes_since_gc
).
and_return
(
10
)
expect
(
subject
.
needed?
).
to
eq
(
true
)
end
end
end
\ No newline at end of file
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