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
dc55d729
Commit
dc55d729
authored
Jun 14, 2017
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Check which repositories should be synced
parent
b5578fb5
Changes
2
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
207 additions
and
70 deletions
+207
-70
app/services/geo/repository_sync_service.rb
app/services/geo/repository_sync_service.rb
+69
-21
spec/services/geo/repository_sync_service_spec.rb
spec/services/geo/repository_sync_service_spec.rb
+138
-49
No files found.
app/services/geo/repository_sync_service.rb
View file @
dc55d729
...
...
@@ -12,8 +12,8 @@ module Geo
def
execute
try_obtain_lease
do
log
(
'Started repository sync'
)
s
tarted_at
,
finished_at
=
fetch_repositories
update_registry
(
started_at
,
finished_at
)
s
ync_project_repository
sync_wiki_repository
log
(
'Finished repository sync'
)
end
rescue
ActiveRecord
::
RecordNotFound
...
...
@@ -26,14 +26,51 @@ module Geo
@project
||=
Project
.
find
(
project_id
)
end
def
fetch_repositories
def
registry
@registry
||=
Geo
::
ProjectRegistry
.
find_or_initialize_by
(
project_id:
project_id
)
end
def
sync_project_repository
return
unless
sync_repository?
started_at
,
finished_at
=
fetch_project_repository
update_registry
(
:repository
,
started_at
,
finished_at
)
expire_repository_caches
end
def
sync_repository?
return
true
if
registry
.
resync_repository?
return
true
if
registry
.
last_repository_successful_sync_at
.
nil?
return
true
if
registry
.
last_repository_synced_at
.
nil?
false
end
def
sync_wiki_repository
return
unless
sync_wiki?
started_at
,
finished_at
=
fetch_wiki_repository
update_registry
(
:wiki
,
started_at
,
finished_at
)
end
def
sync_wiki?
return
true
if
registry
.
resync_wiki?
return
true
if
registry
.
last_wiki_successful_sync_at
.
nil?
return
true
if
registry
.
last_wiki_synced_at
.
nil?
false
end
def
fetch_project_repository
return
unless
sync_repository?
log
(
'Fetching project repository'
)
started_at
=
DateTime
.
now
finished_at
=
nil
begin
fetch_project_repository
fetch_wiki_repository
expire_repository_caches
project
.
create_repository
unless
project
.
repository_exists?
project
.
repository
.
fetch_geo_mirror
(
ssh_url_to_repo
)
finished_at
=
DateTime
.
now
rescue
Gitlab
::
Shell
::
Error
=>
e
...
...
@@ -47,18 +84,25 @@ module Geo
[
started_at
,
finished_at
]
end
def
fetch_project_repository
log
(
'Fetching project repository'
)
project
.
create_repository
unless
project
.
repository_exists?
project
.
repository
.
fetch_geo_mirror
(
ssh_url_to_repo
)
end
def
fetch_wiki_repository
return
unless
sync_wiki?
log
(
'Fetching wiki repository'
)
started_at
=
DateTime
.
now
finished_at
=
nil
begin
# Second .wiki call returns a Gollum::Wiki, and it will always create the physical repository when not found
if
project
.
wiki
.
wiki
.
exist?
log
(
'Fetching wiki repository'
)
project
.
wiki
.
repository
.
fetch_geo_mirror
(
ssh_url_to_wiki
)
end
finished_at
=
DateTime
.
now
rescue
Gitlab
::
Shell
::
Error
=>
e
Rails
.
logger
.
error
(
"
#{
self
.
class
.
name
}
: Error syncing wiki repository for project
#{
project
.
path_with_namespace
}
:
#{
e
}
"
)
end
[
started_at
,
finished_at
]
end
def
expire_repository_caches
...
...
@@ -84,11 +128,15 @@ module Geo
Gitlab
::
ExclusiveLease
.
cancel
(
lease_key
,
repository_lease
)
end
def
update_registry
(
started_at
,
finished_at
)
log
(
'Updating repository sync information'
)
registry
=
Geo
::
ProjectRegistry
.
find_or_initialize_by
(
project_id:
project_id
)
registry
.
last_repository_synced_at
=
started_at
registry
.
last_repository_successful_sync_at
=
finished_at
if
finished_at
def
update_registry
(
type
,
started_at
,
finished_at
)
log
(
'Updating #{type} sync information'
)
registry
.
public_send
(
"last_
#{
type
}
_synced_at="
,
started_at
)
if
finished_at
registry
.
public_send
(
"last_
#{
type
}
_successful_sync_at="
,
started_at
)
registry
.
public_send
(
"resync_
#{
type
}
="
,
false
)
end
registry
.
save
end
...
...
spec/services/geo/repository_sync_service_spec.rb
View file @
dc55d729
This diff is collapsed.
Click to expand it.
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