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
1cc8a169
Commit
1cc8a169
authored
Jul 05, 2017
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Store the time the sync started before fetching the repositories
parent
9d3b8832
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
85 additions
and
68 deletions
+85
-68
app/services/geo/repository_sync_service.rb
app/services/geo/repository_sync_service.rb
+13
-20
app/workers/geo_repository_sync_worker.rb
app/workers/geo_repository_sync_worker.rb
+1
-0
spec/services/geo/repository_sync_service_spec.rb
spec/services/geo/repository_sync_service_spec.rb
+71
-48
No files found.
app/services/geo/repository_sync_service.rb
View file @
1cc8a169
...
@@ -33,8 +33,7 @@ module Geo
...
@@ -33,8 +33,7 @@ module Geo
def
sync_project_repository
def
sync_project_repository
return
unless
sync_repository?
return
unless
sync_repository?
started_at
,
finished_at
=
fetch_project_repository
fetch_project_repository
update_registry
(
:repository
,
started_at
,
finished_at
)
expire_repository_caches
expire_repository_caches
end
end
...
@@ -47,8 +46,7 @@ module Geo
...
@@ -47,8 +46,7 @@ module Geo
def
sync_wiki_repository
def
sync_wiki_repository
return
unless
sync_wiki?
return
unless
sync_wiki?
started_at
,
finished_at
=
fetch_wiki_repository
fetch_wiki_repository
update_registry
(
:wiki
,
started_at
,
finished_at
)
end
end
def
sync_wiki?
def
sync_wiki?
...
@@ -58,17 +56,14 @@ module Geo
...
@@ -58,17 +56,14 @@ module Geo
end
end
def
fetch_project_repository
def
fetch_project_repository
return
unless
sync_repository?
log
(
'Fetching project repository'
)
log
(
'Fetching project repository'
)
started_at
=
DateTime
.
now
update_registry
(
:repository
,
started_at:
DateTime
.
now
)
finished_at
=
nil
begin
begin
project
.
ensure_repository
project
.
ensure_repository
project
.
repository
.
fetch_geo_mirror
(
ssh_url_to_repo
)
project
.
repository
.
fetch_geo_mirror
(
ssh_url_to_repo
)
finished_at
=
DateTime
.
now
update_registry
(
:repository
,
finished_at:
DateTime
.
now
)
rescue
Gitlab
::
Shell
::
Error
=>
e
rescue
Gitlab
::
Shell
::
Error
=>
e
Rails
.
logger
.
error
(
"
#{
self
.
class
.
name
}
: Error syncing repository for project
#{
project
.
path_with_namespace
}
:
#{
e
}
"
)
Rails
.
logger
.
error
(
"
#{
self
.
class
.
name
}
: Error syncing repository for project
#{
project
.
path_with_namespace
}
:
#{
e
}
"
)
rescue
Gitlab
::
Git
::
Repository
::
NoRepository
=>
e
rescue
Gitlab
::
Git
::
Repository
::
NoRepository
=>
e
...
@@ -76,27 +71,20 @@ module Geo
...
@@ -76,27 +71,20 @@ module Geo
log
(
'Expiring caches'
)
log
(
'Expiring caches'
)
project
.
repository
.
after_create
project
.
repository
.
after_create
end
end
[
started_at
,
finished_at
]
end
end
def
fetch_wiki_repository
def
fetch_wiki_repository
return
unless
sync_wiki?
log
(
'Fetching wiki repository'
)
log
(
'Fetching wiki repository'
)
started_at
=
DateTime
.
now
update_registry
(
:wiki
,
started_at:
DateTime
.
now
)
finished_at
=
nil
begin
begin
project
.
wiki
.
ensure_repository
project
.
wiki
.
ensure_repository
project
.
wiki
.
repository
.
fetch_geo_mirror
(
ssh_url_to_wiki
)
project
.
wiki
.
repository
.
fetch_geo_mirror
(
ssh_url_to_wiki
)
finished_at
=
DateTime
.
now
update_registry
(
:wiki
,
finished_at:
DateTime
.
now
)
rescue
Gitlab
::
Git
::
Repository
::
NoRepository
,
Gitlab
::
Shell
::
Error
,
ProjectWiki
::
CouldNotCreateWikiError
=>
e
rescue
Gitlab
::
Git
::
Repository
::
NoRepository
,
Gitlab
::
Shell
::
Error
,
ProjectWiki
::
CouldNotCreateWikiError
=>
e
Rails
.
logger
.
error
(
"
#{
self
.
class
.
name
}
: Error syncing wiki repository for project
#{
project
.
path_with_namespace
}
:
#{
e
}
"
)
Rails
.
logger
.
error
(
"
#{
self
.
class
.
name
}
: Error syncing wiki repository for project
#{
project
.
path_with_namespace
}
:
#{
e
}
"
)
end
end
[
started_at
,
finished_at
]
end
end
def
expire_repository_caches
def
expire_repository_caches
...
@@ -122,9 +110,14 @@ module Geo
...
@@ -122,9 +110,14 @@ module Geo
Gitlab
::
ExclusiveLease
.
cancel
(
lease_key
,
repository_lease
)
Gitlab
::
ExclusiveLease
.
cancel
(
lease_key
,
repository_lease
)
end
end
def
update_registry
(
type
,
started_at
,
finished_at
)
def
update_registry
(
type
,
started_at:
nil
,
finished_at:
nil
)
return
unless
started_at
||
finished_at
log
(
"Updating
#{
type
}
sync information"
)
log
(
"Updating
#{
type
}
sync information"
)
if
started_at
registry
.
public_send
(
"last_
#{
type
}
_synced_at="
,
started_at
)
registry
.
public_send
(
"last_
#{
type
}
_synced_at="
,
started_at
)
end
if
finished_at
if
finished_at
registry
.
public_send
(
"last_
#{
type
}
_successful_sync_at="
,
finished_at
)
registry
.
public_send
(
"last_
#{
type
}
_successful_sync_at="
,
finished_at
)
...
...
app/workers/geo_repository_sync_worker.rb
View file @
1cc8a169
...
@@ -30,6 +30,7 @@ class GeoRepositorySyncWorker
...
@@ -30,6 +30,7 @@ class GeoRepositorySyncWorker
try_obtain_lease
do
|
lease
|
try_obtain_lease
do
|
lease
|
Geo
::
RepositorySyncService
.
new
(
project_id
).
execute
Geo
::
RepositorySyncService
.
new
(
project_id
).
execute
end
end
rescue
ActiveRecord
::
RecordNotFound
rescue
ActiveRecord
::
RecordNotFound
logger
.
error
(
"Couldn't find project with ID=
#{
project_id
}
, skipping syncing"
)
logger
.
error
(
"Couldn't find project with ID=
#{
project_id
}
, skipping syncing"
)
next
next
...
...
spec/services/geo/repository_sync_service_spec.rb
View file @
1cc8a169
...
@@ -59,43 +59,75 @@ describe Geo::RepositorySyncService, services: true do
...
@@ -59,43 +59,75 @@ describe Geo::RepositorySyncService, services: true do
expect
{
subject
.
execute
}.
to
change
(
Geo
::
ProjectRegistry
,
:count
).
by
(
1
)
expect
{
subject
.
execute
}.
to
change
(
Geo
::
ProjectRegistry
,
:count
).
by
(
1
)
end
end
it
'sets last_repository_successful_sync_at when repository sync succeed'
do
context
'when repository sync succeed'
do
let
(
:registry
)
{
Geo
::
ProjectRegistry
.
find_by
(
project_id:
project
.
id
)
}
before
do
subject
.
execute
subject
.
execute
end
registry
=
Geo
::
ProjectRegistry
.
find_by
(
project_id:
project
.
id
)
it
'sets last_repository_synced_at'
do
expect
(
registry
.
last_repository_synced_at
).
not_to
be_nil
end
it
'sets last_repository_successful_sync_at'
do
expect
(
registry
.
last_repository_successful_sync_at
).
not_to
be_nil
expect
(
registry
.
last_repository_successful_sync_at
).
not_to
be_nil
end
end
end
it
'resets last_repository_successful_sync_at when repository sync fail'
do
context
'when repository sync fail'
do
let
(
:registry
)
{
Geo
::
ProjectRegistry
.
find_by
(
project_id:
project
.
id
)
}
before
do
allow_any_instance_of
(
Repository
).
to
receive
(
:fetch_geo_mirror
).
with
(
/
#{
project
.
path_with_namespace
}
\.git/
)
{
raise
Gitlab
::
Shell
::
Error
}
allow_any_instance_of
(
Repository
).
to
receive
(
:fetch_geo_mirror
).
with
(
/
#{
project
.
path_with_namespace
}
\.git/
)
{
raise
Gitlab
::
Shell
::
Error
}
subject
.
execute
subject
.
execute
end
registry
=
Geo
::
ProjectRegistry
.
find_by
(
project_id:
project
.
id
)
it
'sets last_repository_synced_at'
do
expect
(
registry
.
last_repository_synced_at
).
not_to
be_nil
end
it
'resets last_repository_successful_sync_at'
do
expect
(
registry
.
last_repository_successful_sync_at
).
to
be_nil
expect
(
registry
.
last_repository_successful_sync_at
).
to
be_nil
end
end
end
context
'when wiki sync succeed'
do
let
(
:registry
)
{
Geo
::
ProjectRegistry
.
find_by
(
project_id:
project
.
id
)
}
it
'sets last_wiki_successful_sync_at when wiki sync succeed'
do
before
do
subject
.
execute
subject
.
execute
end
registry
=
Geo
::
ProjectRegistry
.
find_by
(
project_id:
project
.
id
)
it
'sets last_wiki_synced_at'
do
expect
(
registry
.
last_wiki_synced_at
).
not_to
be_nil
end
it
'sets last_wiki_successful_sync_at'
do
expect
(
registry
.
last_wiki_successful_sync_at
).
not_to
be_nil
expect
(
registry
.
last_wiki_successful_sync_at
).
not_to
be_nil
end
end
end
it
'resets last_wiki_successful_sync_at when wiki sync fail'
do
context
'when wiki sync fail'
do
let
(
:registry
)
{
Geo
::
ProjectRegistry
.
find_by
(
project_id:
project
.
id
)
}
before
do
allow_any_instance_of
(
Repository
).
to
receive
(
:fetch_geo_mirror
).
with
(
/
#{
project
.
path_with_namespace
}
\.wiki.git/
)
{
raise
Gitlab
::
Shell
::
Error
}
allow_any_instance_of
(
Repository
).
to
receive
(
:fetch_geo_mirror
).
with
(
/
#{
project
.
path_with_namespace
}
\.wiki.git/
)
{
raise
Gitlab
::
Shell
::
Error
}
subject
.
execute
subject
.
execute
end
registry
=
Geo
::
ProjectRegistry
.
find_by
(
project_id:
project
.
id
)
it
'sets last_wiki_synced_at'
do
expect
(
registry
.
last_wiki_synced_at
).
not_to
be_nil
end
it
'resets last_wiki_successful_sync_at'
do
expect
(
registry
.
last_wiki_successful_sync_at
).
to
be_nil
expect
(
registry
.
last_wiki_successful_sync_at
).
to
be_nil
end
end
end
end
end
end
end
context
'when project has been synced'
do
context
'when project has been synced'
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:project
)
{
create
(
:project
)
}
...
@@ -122,7 +154,7 @@ describe Geo::RepositorySyncService, services: true do
...
@@ -122,7 +154,7 @@ describe Geo::RepositorySyncService, services: true do
expect
{
subject
.
execute
}.
not_to
change
(
Geo
::
ProjectRegistry
,
:count
)
expect
{
subject
.
execute
}.
not_to
change
(
Geo
::
ProjectRegistry
,
:count
)
end
end
it
'does not update last
_repository_successful_sync_at
'
do
it
'does not update last
repository sync times
'
do
subject
.
execute
subject
.
execute
registry
.
reload
registry
.
reload
...
@@ -131,7 +163,7 @@ describe Geo::RepositorySyncService, services: true do
...
@@ -131,7 +163,7 @@ describe Geo::RepositorySyncService, services: true do
expect
(
registry
.
last_repository_successful_sync_at
).
to
be_within
(
1
.
minute
).
of
(
last_repository_synced_at
)
expect
(
registry
.
last_repository_successful_sync_at
).
to
be_within
(
1
.
minute
).
of
(
last_repository_synced_at
)
end
end
it
'does not update last
_wiki_successful_sync_at
'
do
it
'does not update last
wiki sync times
'
do
subject
.
execute
subject
.
execute
registry
.
reload
registry
.
reload
...
@@ -159,19 +191,24 @@ describe Geo::RepositorySyncService, services: true do
...
@@ -159,19 +191,24 @@ describe Geo::RepositorySyncService, services: true do
end
end
context
'tracking database'
do
context
'tracking database'
do
it
'sets last_repository_successful_sync_at'
do
before
do
subject
.
execute
subject
.
execute
registry
.
reload
registry
.
reload
end
expect
(
registry
.
last_repository_successful_sync_at
).
not_to
be_nil
it
'updates last_repository_synced_at'
do
expect
(
registry
.
last_repository_synced_at
).
to
be_within
(
1
.
minute
).
of
(
DateTime
.
now
)
end
end
it
'sets last_wiki_successful_sync_at'
do
it
'sets last_repository_successful_sync_at'
do
subject
.
execute
expect
(
registry
.
last_repository_successful_sync_at
).
not_to
be_nil
end
registry
.
reload
it
'updates last_wiki_synced_at'
do
expect
(
registry
.
last_wiki_synced_at
).
to
be_within
(
1
.
minute
).
of
(
DateTime
.
now
)
end
it
'sets last_wiki_successful_sync_at'
do
expect
(
registry
.
last_wiki_successful_sync_at
).
not_to
be_nil
expect
(
registry
.
last_wiki_successful_sync_at
).
not_to
be_nil
end
end
end
end
...
@@ -211,29 +248,22 @@ describe Geo::RepositorySyncService, services: true do
...
@@ -211,29 +248,22 @@ describe Geo::RepositorySyncService, services: true do
end
end
context
'tracking database'
do
context
'tracking database'
do
it
'updates last_repository_successful_sync_at'
do
before
do
subject
.
execute
subject
.
execute
registry
.
reload
registry
.
reload
end
it
'updates last repository sync times'
do
expect
(
registry
.
last_repository_synced_at
).
to
be_within
(
1
.
minute
).
of
(
DateTime
.
now
)
expect
(
registry
.
last_repository_synced_at
).
to
be_within
(
1
.
minute
).
of
(
DateTime
.
now
)
expect
(
registry
.
last_repository_successful_sync_at
).
to
be_within
(
1
.
minute
).
of
(
DateTime
.
now
)
expect
(
registry
.
last_repository_successful_sync_at
).
to
be_within
(
1
.
minute
).
of
(
DateTime
.
now
)
end
end
it
'does not update last_wiki_successful_sync_at'
do
it
'does not update last wiki sync times'
do
subject
.
execute
registry
.
reload
expect
(
registry
.
last_wiki_synced_at
).
to
be_within
(
1
.
minute
).
of
(
last_wiki_synced_at
)
expect
(
registry
.
last_wiki_synced_at
).
to
be_within
(
1
.
minute
).
of
(
last_wiki_synced_at
)
expect
(
registry
.
last_wiki_successful_sync_at
).
to
be_within
(
1
.
minute
).
of
(
last_wiki_synced_at
)
expect
(
registry
.
last_wiki_successful_sync_at
).
to
be_within
(
1
.
minute
).
of
(
last_wiki_synced_at
)
end
end
it
'resets resync_repository'
do
it
'resets resync_repository'
do
subject
.
execute
registry
.
reload
expect
(
registry
.
resync_repository
).
to
be
false
expect
(
registry
.
resync_repository
).
to
be
false
end
end
end
end
...
@@ -271,29 +301,22 @@ describe Geo::RepositorySyncService, services: true do
...
@@ -271,29 +301,22 @@ describe Geo::RepositorySyncService, services: true do
end
end
context
'tracking database'
do
context
'tracking database'
do
it
'updates last_wiki_successful_sync_at'
do
before
do
subject
.
execute
subject
.
execute
registry
.
reload
registry
.
reload
end
it
'updates last wiki sync times'
do
expect
(
registry
.
last_wiki_synced_at
).
to
be_within
(
1
.
minute
).
of
(
DateTime
.
now
)
expect
(
registry
.
last_wiki_synced_at
).
to
be_within
(
1
.
minute
).
of
(
DateTime
.
now
)
expect
(
registry
.
last_wiki_successful_sync_at
).
to
be_within
(
1
.
minute
).
of
(
DateTime
.
now
)
expect
(
registry
.
last_wiki_successful_sync_at
).
to
be_within
(
1
.
minute
).
of
(
DateTime
.
now
)
end
end
it
'does not update last_repository_successful_sync_at'
do
it
'does not update last repository sync times'
do
subject
.
execute
registry
.
reload
expect
(
registry
.
last_repository_synced_at
).
to
be_within
(
1
.
minute
).
of
(
last_repository_synced_at
)
expect
(
registry
.
last_repository_synced_at
).
to
be_within
(
1
.
minute
).
of
(
last_repository_synced_at
)
expect
(
registry
.
last_repository_successful_sync_at
).
to
be_within
(
1
.
minute
).
of
(
last_repository_synced_at
)
expect
(
registry
.
last_repository_successful_sync_at
).
to
be_within
(
1
.
minute
).
of
(
last_repository_synced_at
)
end
end
it
'resets resync_wiki'
do
it
'resets resync_wiki'
do
subject
.
execute
registry
.
reload
expect
(
registry
.
resync_wiki
).
to
be
false
expect
(
registry
.
resync_wiki
).
to
be
false
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