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
a395d194
Commit
a395d194
authored
Jul 26, 2017
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add group restrictions to Geo::RepositorySyncWorker
parent
ea0674fc
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
13 deletions
+51
-13
app/workers/geo/repository_sync_worker.rb
app/workers/geo/repository_sync_worker.rb
+27
-12
spec/workers/geo/repository_sync_worker_spec.rb
spec/workers/geo/repository_sync_worker_spec.rb
+24
-1
No files found.
app/workers/geo/repository_sync_worker.rb
View file @
a395d194
...
...
@@ -16,21 +16,36 @@ module Geo
end
def
load_pending_resources
project_ids_not_synced
=
find_project_ids_not_synced
project_ids_updated_recently
=
find_project_ids_updated_recently
restricted_project_ids
=
Gitlab
::
Geo
.
current_node
.
project_ids
project_ids_not_synced
=
find_project_ids_not_synced
(
restricted_project_ids
)
project_ids_updated_recently
=
find_project_ids_updated_recently
(
restricted_project_ids
)
interleave
(
project_ids_not_synced
,
project_ids_updated_recently
)
end
def
find_project_ids_not_synced
Project
.
where
.
not
(
id:
Geo
::
ProjectRegistry
.
synced
.
pluck
(
:project_id
))
def
find_project_ids_not_synced
(
restricted_project_ids
)
relation
=
if
restricted_project_ids
Project
.
where
(
id:
restricted_project_ids
)
else
Project
.
all
end
relation
.
where
.
not
(
id:
Geo
::
ProjectRegistry
.
synced
.
pluck
(
:project_id
))
.
order
(
last_repository_updated_at: :desc
)
.
limit
(
db_retrieve_batch_size
)
.
pluck
(
:id
)
end
def
find_project_ids_updated_recently
Geo
::
ProjectRegistry
.
dirty
def
find_project_ids_updated_recently
(
restricted_project_ids
)
relation
=
if
restricted_project_ids
Geo
::
ProjectRegistry
.
where
(
project_id:
restricted_project_ids
)
else
Geo
::
ProjectRegistry
.
all
end
relation
.
dirty
.
order
(
Gitlab
::
Database
.
nulls_first_order
(
:last_repository_synced_at
,
:desc
))
.
limit
(
db_retrieve_batch_size
)
.
pluck
(
:project_id
)
...
...
spec/workers/geo/repository_sync_worker_spec.rb
View file @
a395d194
...
...
@@ -3,7 +3,8 @@ require 'spec_helper'
describe
Geo
::
RepositorySyncWorker
do
let!
(
:primary
)
{
create
(
:geo_node
,
:primary
,
host:
'primary-geo-node'
)
}
let!
(
:secondary
)
{
create
(
:geo_node
,
:current
)
}
let!
(
:project_1
)
{
create
(
:project
)
}
let
(
:group
)
{
create
(
:group
)
}
let!
(
:project_1
)
{
create
(
:project
,
group:
group
)
}
let!
(
:project_2
)
{
create
(
:project
)
}
subject
{
described_class
.
new
}
...
...
@@ -62,5 +63,27 @@ describe Geo::RepositorySyncWorker do
subject
.
perform
end
context
'when node have group restrictions'
do
before
do
allow
(
Gitlab
::
Geo
).
to
receive
(
:current_node
).
and_return
(
secondary
)
secondary
.
update_attribute
(
:groups
,
[
group
])
end
it
'does not perform Geo::ProjectSyncWorker for projects that do not belong to selected groups to replicate'
do
expect
(
Geo
::
ProjectSyncWorker
).
to
receive
(
:perform_in
).
once
.
and_return
(
spy
)
subject
.
perform
end
it
'does not perform Geo::ProjectSyncWorker for synced projects updated recently that do not belong to selected groups to replicate'
do
create
(
:geo_project_registry
,
:synced
,
:repository_dirty
,
project:
project_1
)
create
(
:geo_project_registry
,
:synced
,
:repository_dirty
,
project:
project_2
)
expect
(
Geo
::
ProjectSyncWorker
).
to
receive
(
:perform_in
).
once
.
and_return
(
spy
)
subject
.
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