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
45bc7d93
Commit
45bc7d93
authored
Aug 01, 2017
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Perform repositories clean up on Geo::RepositoriesCleanUpWorker
parent
d7b49240
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
68 additions
and
6 deletions
+68
-6
app/workers/geo/repositories_clean_up_worker.rb
app/workers/geo/repositories_clean_up_worker.rb
+32
-6
spec/workers/geo/repositories_clean_up_worker_spec.rb
spec/workers/geo/repositories_clean_up_worker_spec.rb
+36
-0
No files found.
app/workers/geo/repositories_clean_up_worker.rb
View file @
45bc7d93
...
...
@@ -3,15 +3,41 @@ module Geo
include
Sidekiq
::
Worker
include
GeoQueue
BATCH_SIZE
=
250
def
perform
(
geo_node_id
)
geo_node
=
GeoNode
.
find
(
geo_node_id
)
restricted_project_ids
=
geo_node
.
project_ids
return
unless
restricted_project_ids
Project
.
where
.
not
(
id:
restricted_project_ids
).
find_in_batches
(
batch_size:
BATCH_SIZE
)
do
|
batch
|
batch
.
each
do
|
project
|
clean_up_repositories
(
project
)
end
end
rescue
ActiveRecord
::
RecordNotFound
=>
e
Gitlab
::
Geo
::
Logger
.
error
(
class:
self
.
class
.
name
,
message:
'Could not find Geo node, skipping repositories clean up'
,
geo_node_id:
geo_node_id
,
error:
e
)
log_error
(
'Could not find Geo node, skipping repositories clean up'
,
geo_node_id:
geo_node_id
,
error:
e
)
end
private
def
clean_up_repositories
(
project
)
job_id
=
::
GeoRepositoryDestroyWorker
.
perform_async
(
project
.
id
,
project
.
name
,
project
.
full_path
)
if
job_id
log_info
(
'Repository cleaned up'
,
project_id:
project
.
id
,
full_path:
project
.
full_path
,
job_id:
job_id
)
else
log_error
(
'Could not clean up repository'
,
project_id:
project
.
id
,
full_path:
project
.
full_path
)
end
end
def
log_info
(
message
,
params
=
{})
Gitlab
::
Geo
::
Logger
.
info
({
class:
self
.
class
.
name
,
message:
message
}.
merge
(
params
))
end
def
log_error
(
message
,
params
=
{})
Gitlab
::
Geo
::
Logger
.
error
({
class:
self
.
class
.
name
,
message:
message
}.
merge
(
params
))
end
end
end
spec/workers/geo/repositories_clean_up_worker_spec.rb
0 → 100644
View file @
45bc7d93
require
'spec_helper'
describe
Geo
::
RepositoriesCleanUpWorker
do
let!
(
:geo_node
)
{
create
(
:geo_node
)
}
let
(
:group
)
{
create
(
:group
)
}
let!
(
:project_1
)
{
create
(
:empty_project
,
group:
group
)
}
let!
(
:project_2
)
{
create
(
:empty_project
)
}
describe
'#perform'
do
context
'when node have namespace restrictions'
do
it
'performs GeoRepositoryDestroyWorker for each project that do not belong to selected namespaces to replicate'
do
geo_node
.
update_attribute
(
:namespaces
,
[
group
])
expect
(
GeoRepositoryDestroyWorker
).
to
receive
(
:perform_async
)
.
with
(
project_2
.
id
,
project_2
.
name
,
project_2
.
full_path
)
.
once
.
and_return
(
1
)
subject
.
perform
(
geo_node
.
id
)
end
end
context
'when does not node have namespace restrictions'
do
it
'does not perform GeoRepositoryDestroyWorker'
do
expect
(
GeoRepositoryDestroyWorker
).
not_to
receive
(
:perform_async
)
subject
.
perform
(
geo_node
.
id
)
end
end
context
'when Geo node could not be found'
do
it
'does not raise an error'
do
expect
{
subject
.
perform
(
-
1
)
}.
not_to
raise_error
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