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
b2d0410c
Commit
b2d0410c
authored
Dec 01, 2017
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor code based on feedback
parent
5ad48b83
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
22 additions
and
33 deletions
+22
-33
app/services/geo/base_sync_service.rb
app/services/geo/base_sync_service.rb
+10
-3
app/services/geo/repository_sync_service.rb
app/services/geo/repository_sync_service.rb
+4
-13
app/services/geo/wiki_sync_service.rb
app/services/geo/wiki_sync_service.rb
+4
-13
doc/api/geo_nodes.md
doc/api/geo_nodes.md
+2
-2
lib/api/geo_nodes.rb
lib/api/geo_nodes.rb
+2
-2
No files found.
app/services/geo/base_sync_service.rb
View file @
b2d0410c
...
...
@@ -127,13 +127,11 @@ module Geo
@registry
||=
Geo
::
ProjectRegistry
.
find_or_initialize_by
(
project_id:
project
.
id
)
end
def
update_registry
(
started_at:
nil
,
finished_at:
nil
)
def
update_registry
!
(
started_at:
nil
,
finished_at:
nil
,
attrs:
{}
)
return
unless
started_at
||
finished_at
log_info
(
"Updating
#{
type
}
sync information"
)
attrs
=
{}
if
started_at
attrs
[
"last_
#{
type
}
_synced_at"
]
=
started_at
attrs
[
"
#{
type
}
_retry_count"
]
=
retry_count
+
1
...
...
@@ -150,6 +148,15 @@ module Geo
registry
.
update!
(
attrs
)
end
def
fail_registry!
(
message
,
error
,
attrs
=
{})
log_error
(
message
,
error
)
attrs
[
"last_
#{
type
}
_sync_failure"
]
=
"
#{
message
}
:
#{
error
.
message
}
"
attrs
[
"
#{
type
}
_retry_count"
]
=
retry_count
+
1
registry
.
update!
(
attrs
)
end
def
type
self
.
class
.
type
end
...
...
app/services/geo/repository_sync_service.rb
View file @
b2d0410c
...
...
@@ -11,7 +11,7 @@ module Geo
def
fetch_project_repository
(
redownload
)
log_info
(
'Trying to fetch project repository'
)
update_registry
(
started_at:
DateTime
.
now
)
update_registry
!
(
started_at:
DateTime
.
now
)
if
redownload
log_info
(
'Redownloading repository'
)
...
...
@@ -22,19 +22,17 @@ module Geo
fetch_geo_mirror
(
project
.
repository
)
end
update_registry
(
finished_at:
DateTime
.
now
,
last_repository_sync_failure:
nil
)
update_registry
!
(
finished_at:
DateTime
.
now
,
attrs:
{
last_repository_sync_failure:
nil
}
)
log_info
(
'Finished repository sync'
,
update_delay_s:
update_delay_in_seconds
,
download_time_s:
download_time_in_seconds
)
rescue
Gitlab
::
Shell
::
Error
,
Gitlab
::
Git
::
RepositoryMirroring
::
RemoteError
,
Geo
::
EmptyCloneUrlPrefixError
=>
e
fail_registry
(
'Error syncing repository'
,
e
)
fail_registry
!
(
'Error syncing repository'
,
e
)
rescue
Gitlab
::
Git
::
Repository
::
NoRepository
=>
e
fail_registry
(
'Invalid repository'
,
e
)
log_info
(
'Setting force_to_redownload flag'
)
registry
.
update
(
force_to_redownload_repository:
true
)
fail_registry!
(
'Invalid repository'
,
e
,
force_to_redownload_repository:
true
)
log_info
(
'Expiring caches'
)
project
.
repository
.
after_create
...
...
@@ -55,13 +53,6 @@ module Geo
project
.
repository
end
def
fail_registry
(
message
,
error
)
log_error
(
message
,
error
)
registry
.
update!
(
last_repository_sync_failure:
"
#{
message
}
:
#{
error
.
message
}
"
,
repository_retry_count:
retry_count
+
1
)
end
def
retry_count
registry
.
public_send
(
"
#{
type
}
_retry_count"
)
||
-
1
# rubocop:disable GitlabSecurity/PublicSend
end
...
...
app/services/geo/wiki_sync_service.rb
View file @
b2d0410c
...
...
@@ -10,7 +10,7 @@ module Geo
def
fetch_wiki_repository
(
redownload
)
log_info
(
'Fetching wiki repository'
)
update_registry
(
started_at:
DateTime
.
now
)
update_registry
!
(
started_at:
DateTime
.
now
)
if
redownload
log_info
(
'Redownloading wiki'
)
...
...
@@ -21,7 +21,7 @@ module Geo
fetch_geo_mirror
(
project
.
wiki
.
repository
)
end
update_registry
(
finished_at:
DateTime
.
now
,
last_wiki_sync_failure:
nil
)
update_registry
!
(
finished_at:
DateTime
.
now
,
attrs:
{
last_wiki_sync_failure:
nil
}
)
log_info
(
'Finished wiki sync'
,
update_delay_s:
update_delay_in_seconds
,
...
...
@@ -30,12 +30,10 @@ module Geo
Gitlab
::
Shell
::
Error
,
ProjectWiki
::
CouldNotCreateWikiError
,
Geo
::
EmptyCloneUrlPrefixError
=>
e
fail_registry
(
'Error syncing wiki repository'
,
e
)
fail_registry
!
(
'Error syncing wiki repository'
,
e
)
rescue
Gitlab
::
Git
::
Repository
::
NoRepository
=>
e
fail_registry
(
'Invalid wiki'
,
e
)
log_info
(
'Setting force_to_redownload flag'
)
registry
.
update
(
force_to_redownload_wiki:
true
)
fail_registry!
(
'Invalid wiki'
,
e
,
force_to_redownload_wiki:
true
)
ensure
clean_up_temporary_repository
if
redownload
end
...
...
@@ -48,13 +46,6 @@ module Geo
project
.
wiki
.
repository
end
def
fail_registry
(
message
,
error
)
log_error
(
message
,
error
)
registry
.
update!
(
last_wiki_sync_failure:
"
#{
message
}
:
#{
error
.
message
}
"
,
wiki_retry_count:
retry_count
+
1
)
end
def
retry_count
registry
.
public_send
(
"
#{
type
}
_retry_count"
)
||
-
1
# rubocop:disable GitlabSecurity/PublicSend
end
...
...
doc/api/geo_nodes.md
View file @
b2d0410c
...
...
@@ -149,9 +149,9 @@ GET /geo_nodes/:id/failures
| Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
|
`type`
| string | no | Type of failure (
repository/wiki
) |
|
`type`
| string | no | Type of failure (
`repository`
/
`wiki`
) |
This
function takes pagination parameters
`page`
and
`per_page`
to limit the list of failures
.
This
endpoint uses
[
Pagination
](
README.md#pagination
)
.
```
bash
curl
--header
"PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK"
https://gitlab.example.com/api/v4/geo_nodes/2/failures
...
...
lib/api/geo_nodes.rb
View file @
b2d0410c
...
...
@@ -81,7 +81,7 @@ module API
# Get project registry failures for the current Geo node
#
# Example request:
# GET /geo_nodes/:id/failures
/:type
# GET /geo_nodes/:id/failures
desc
'Get project registry failures for the current Geo node'
do
success
Entities
::
GeoNode
end
...
...
@@ -95,7 +95,7 @@ module API
forbidden!
(
'Geo node is not the current node.'
)
end
geo_node
=
G
eoNode
.
find
(
params
[
:id
])
geo_node
=
G
itlab
::
Geo
.
current_node
not_found
(
'Geo node not found'
)
unless
geo_node
...
...
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