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
ecbc409d
Commit
ecbc409d
authored
Jun 14, 2017
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Perform Geo::RepositorySyncService for dirty projects
parent
ad8e7eb1
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
17 deletions
+21
-17
app/models/geo/project_registry.rb
app/models/geo/project_registry.rb
+1
-0
app/workers/geo_repository_sync_worker.rb
app/workers/geo_repository_sync_worker.rb
+5
-11
spec/workers/geo_repository_sync_worker_spec.rb
spec/workers/geo_repository_sync_worker_spec.rb
+15
-6
No files found.
app/models/geo/project_registry.rb
View file @
ecbc409d
...
...
@@ -3,6 +3,7 @@ class Geo::ProjectRegistry < Geo::BaseRegistry
validates
:project
,
presence:
true
scope
:dirty
,
->
{
where
(
arel_table
[
:resync_repository
].
eq
(
true
).
or
(
arel_table
[
:resync_wiki
].
eq
(
true
)))
}
scope
:failed
,
->
{
where
.
not
(
last_repository_synced_at:
nil
).
where
(
last_repository_successful_sync_at:
nil
)
}
scope
:synced
,
->
{
where
.
not
(
last_repository_synced_at:
nil
,
last_repository_successful_sync_at:
nil
)
}
end
app/workers/geo_repository_sync_worker.rb
View file @
ecbc409d
...
...
@@ -12,7 +12,7 @@ class GeoRepositorySyncWorker
start_time
=
Time
.
now
project_ids_not_synced
=
find_project_ids_not_synced
project_ids_updated_recently
=
find_
synced_
project_ids_updated_recently
project_ids_updated_recently
=
find_project_ids_updated_recently
project_ids
=
interleave
(
project_ids_not_synced
,
project_ids_updated_recently
)
logger
.
info
"Started Geo repository syncing for
#{
project_ids
.
length
}
project(s)"
...
...
@@ -43,24 +43,18 @@ class GeoRepositorySyncWorker
def
find_project_ids_not_synced
Project
.
where
.
not
(
id:
Geo
::
ProjectRegistry
.
synced
.
pluck
(
:project_id
))
.
order
(
last_repository_updated_at: :desc
)
.
limit
(
BATCH_SIZE
)
.
pluck
(
:id
)
end
def
find_synced_project_ids_updated_recently
Geo
::
ProjectRegistry
.
where
(
project_id:
find_project_ids_updated_recently
)
.
where
(
'last_repository_synced_at <= ?'
,
LAST_SYNC_INTERVAL
.
ago
)
.
order
(
last_repository_synced_at: :asc
)
def
find_project_ids_updated_recently
Geo
::
ProjectRegistry
.
dirty
.
order
(
Gitlab
::
Database
.
nulls_first_order
(
:last_repository_synced_at
,
:desc
))
.
limit
(
BATCH_SIZE
)
.
pluck
(
:project_id
)
end
def
find_project_ids_updated_recently
Project
.
where
(
id:
Geo
::
ProjectRegistry
.
synced
.
pluck
(
:project_id
))
.
where
(
'last_repository_updated_at >= ?'
,
LAST_SYNC_INTERVAL
.
ago
)
.
pluck
(
:id
)
end
def
interleave
(
first
,
second
)
if
first
.
length
>=
second
.
length
first
.
zip
(
second
)
...
...
spec/workers/geo_repository_sync_worker_spec.rb
View file @
ecbc409d
...
...
@@ -35,19 +35,28 @@ describe GeoRepositorySyncWorker do
Geo
::
ProjectRegistry
.
create
(
project:
project_1
,
last_repository_synced_at:
2
.
days
.
ago
,
last_repository_successful_sync_at:
2
.
days
.
ago
last_repository_successful_sync_at:
2
.
days
.
ago
,
resync_repository:
true
,
resync_wiki:
false
)
Geo
::
ProjectRegistry
.
create
(
project:
project_2
,
last_repository_synced_at:
2
.
days
.
ago
,
last_repository_successful_sync_at:
2
.
days
.
ago
last_repository_synced_at:
10
.
minutes
.
ago
,
last_repository_successful_sync_at:
10
.
minutes
.
ago
,
resync_repository:
false
,
resync_wiki:
false
)
project_1
.
update_attribute
(
:last_repository_updated_at
,
2
.
days
.
ago
)
project_2
.
update_attribute
(
:last_repository_updated_at
,
10
.
minutes
.
ago
)
Geo
::
ProjectRegistry
.
create
(
project:
create
(
:empty_project
),
last_repository_synced_at:
5
.
minutes
.
ago
,
last_repository_successful_sync_at:
5
.
minutes
.
ago
,
resync_repository:
false
,
resync_wiki:
true
)
expect
(
Geo
::
RepositorySyncService
).
to
receive
(
:new
).
on
ce
.
and_return
(
spy
)
expect
(
Geo
::
RepositorySyncService
).
to
receive
(
:new
).
twi
ce
.
and_return
(
spy
)
subject
.
perform
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