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
Show 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
...
@@ -127,13 +127,11 @@ module Geo
@registry
||=
Geo
::
ProjectRegistry
.
find_or_initialize_by
(
project_id:
project
.
id
)
@registry
||=
Geo
::
ProjectRegistry
.
find_or_initialize_by
(
project_id:
project
.
id
)
end
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
return
unless
started_at
||
finished_at
log_info
(
"Updating
#{
type
}
sync information"
)
log_info
(
"Updating
#{
type
}
sync information"
)
attrs
=
{}
if
started_at
if
started_at
attrs
[
"last_
#{
type
}
_synced_at"
]
=
started_at
attrs
[
"last_
#{
type
}
_synced_at"
]
=
started_at
attrs
[
"
#{
type
}
_retry_count"
]
=
retry_count
+
1
attrs
[
"
#{
type
}
_retry_count"
]
=
retry_count
+
1
...
@@ -150,6 +148,15 @@ module Geo
...
@@ -150,6 +148,15 @@ module Geo
registry
.
update!
(
attrs
)
registry
.
update!
(
attrs
)
end
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
def
type
self
.
class
.
type
self
.
class
.
type
end
end
...
...
app/services/geo/repository_sync_service.rb
View file @
b2d0410c
...
@@ -11,7 +11,7 @@ module Geo
...
@@ -11,7 +11,7 @@ module Geo
def
fetch_project_repository
(
redownload
)
def
fetch_project_repository
(
redownload
)
log_info
(
'Trying to fetch project repository'
)
log_info
(
'Trying to fetch project repository'
)
update_registry
(
started_at:
DateTime
.
now
)
update_registry
!
(
started_at:
DateTime
.
now
)
if
redownload
if
redownload
log_info
(
'Redownloading repository'
)
log_info
(
'Redownloading repository'
)
...
@@ -22,19 +22,17 @@ module Geo
...
@@ -22,19 +22,17 @@ module Geo
fetch_geo_mirror
(
project
.
repository
)
fetch_geo_mirror
(
project
.
repository
)
end
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'
,
log_info
(
'Finished repository sync'
,
update_delay_s:
update_delay_in_seconds
,
update_delay_s:
update_delay_in_seconds
,
download_time_s:
download_time_in_seconds
)
download_time_s:
download_time_in_seconds
)
rescue
Gitlab
::
Shell
::
Error
,
rescue
Gitlab
::
Shell
::
Error
,
Gitlab
::
Git
::
RepositoryMirroring
::
RemoteError
,
Gitlab
::
Git
::
RepositoryMirroring
::
RemoteError
,
Geo
::
EmptyCloneUrlPrefixError
=>
e
Geo
::
EmptyCloneUrlPrefixError
=>
e
fail_registry
(
'Error syncing repository'
,
e
)
fail_registry
!
(
'Error syncing repository'
,
e
)
rescue
Gitlab
::
Git
::
Repository
::
NoRepository
=>
e
rescue
Gitlab
::
Git
::
Repository
::
NoRepository
=>
e
fail_registry
(
'Invalid repository'
,
e
)
log_info
(
'Setting force_to_redownload flag'
)
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'
)
log_info
(
'Expiring caches'
)
project
.
repository
.
after_create
project
.
repository
.
after_create
...
@@ -55,13 +53,6 @@ module Geo
...
@@ -55,13 +53,6 @@ module Geo
project
.
repository
project
.
repository
end
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
def
retry_count
registry
.
public_send
(
"
#{
type
}
_retry_count"
)
||
-
1
# rubocop:disable GitlabSecurity/PublicSend
registry
.
public_send
(
"
#{
type
}
_retry_count"
)
||
-
1
# rubocop:disable GitlabSecurity/PublicSend
end
end
...
...
app/services/geo/wiki_sync_service.rb
View file @
b2d0410c
...
@@ -10,7 +10,7 @@ module Geo
...
@@ -10,7 +10,7 @@ module Geo
def
fetch_wiki_repository
(
redownload
)
def
fetch_wiki_repository
(
redownload
)
log_info
(
'Fetching wiki repository'
)
log_info
(
'Fetching wiki repository'
)
update_registry
(
started_at:
DateTime
.
now
)
update_registry
!
(
started_at:
DateTime
.
now
)
if
redownload
if
redownload
log_info
(
'Redownloading wiki'
)
log_info
(
'Redownloading wiki'
)
...
@@ -21,7 +21,7 @@ module Geo
...
@@ -21,7 +21,7 @@ module Geo
fetch_geo_mirror
(
project
.
wiki
.
repository
)
fetch_geo_mirror
(
project
.
wiki
.
repository
)
end
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'
,
log_info
(
'Finished wiki sync'
,
update_delay_s:
update_delay_in_seconds
,
update_delay_s:
update_delay_in_seconds
,
...
@@ -30,12 +30,10 @@ module Geo
...
@@ -30,12 +30,10 @@ module Geo
Gitlab
::
Shell
::
Error
,
Gitlab
::
Shell
::
Error
,
ProjectWiki
::
CouldNotCreateWikiError
,
ProjectWiki
::
CouldNotCreateWikiError
,
Geo
::
EmptyCloneUrlPrefixError
=>
e
Geo
::
EmptyCloneUrlPrefixError
=>
e
fail_registry
(
'Error syncing wiki repository'
,
e
)
fail_registry
!
(
'Error syncing wiki repository'
,
e
)
rescue
Gitlab
::
Git
::
Repository
::
NoRepository
=>
e
rescue
Gitlab
::
Git
::
Repository
::
NoRepository
=>
e
fail_registry
(
'Invalid wiki'
,
e
)
log_info
(
'Setting force_to_redownload flag'
)
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
ensure
clean_up_temporary_repository
if
redownload
clean_up_temporary_repository
if
redownload
end
end
...
@@ -48,13 +46,6 @@ module Geo
...
@@ -48,13 +46,6 @@ module Geo
project
.
wiki
.
repository
project
.
wiki
.
repository
end
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
def
retry_count
registry
.
public_send
(
"
#{
type
}
_retry_count"
)
||
-
1
# rubocop:disable GitlabSecurity/PublicSend
registry
.
public_send
(
"
#{
type
}
_retry_count"
)
||
-
1
# rubocop:disable GitlabSecurity/PublicSend
end
end
...
...
doc/api/geo_nodes.md
View file @
b2d0410c
...
@@ -149,9 +149,9 @@ GET /geo_nodes/:id/failures
...
@@ -149,9 +149,9 @@ GET /geo_nodes/:id/failures
| Attribute | Type | Required | Description |
| 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
```
bash
curl
--header
"PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK"
https://gitlab.example.com/api/v4/geo_nodes/2/failures
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
...
@@ -81,7 +81,7 @@ module API
# Get project registry failures for the current Geo node
# Get project registry failures for the current Geo node
#
#
# Example request:
# Example request:
# GET /geo_nodes/:id/failures
/:type
# GET /geo_nodes/:id/failures
desc
'Get project registry failures for the current Geo node'
do
desc
'Get project registry failures for the current Geo node'
do
success
Entities
::
GeoNode
success
Entities
::
GeoNode
end
end
...
@@ -95,7 +95,7 @@ module API
...
@@ -95,7 +95,7 @@ module API
forbidden!
(
'Geo node is not the current node.'
)
forbidden!
(
'Geo node is not the current node.'
)
end
end
geo_node
=
G
eoNode
.
find
(
params
[
:id
])
geo_node
=
G
itlab
::
Geo
.
current_node
not_found
(
'Geo node not found'
)
unless
geo_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