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
b4f88515
Commit
b4f88515
authored
Mar 01, 2017
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make GeoNode::Status a proper class rather than a struct
parent
77f15d65
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
63 additions
and
49 deletions
+63
-49
app/models/geo_node.rb
app/models/geo_node.rb
+0
-2
app/models/geo_node_status.rb
app/models/geo_node_status.rb
+43
-0
app/presenters/geo_node_presenter.rb
app/presenters/geo_node_presenter.rb
+3
-25
app/services/geo/node_status_service.rb
app/services/geo/node_status_service.rb
+16
-14
lib/api/geo.rb
lib/api/geo.rb
+1
-8
No files found.
app/models/geo_node.rb
View file @
b4f88515
class
GeoNode
<
ActiveRecord
::
Base
include
Presentable
Status
=
Struct
.
new
(
:health
,
:repositories
,
:repositories_synced
,
:repositories_failed
)
belongs_to
:geo_node_key
,
dependent: :destroy
belongs_to
:oauth_application
,
class_name:
'Doorkeeper::Application'
,
dependent: :destroy
belongs_to
:system_hook
,
dependent: :destroy
...
...
app/models/geo_node_status.rb
0 → 100644
View file @
b4f88515
class
GeoNodeStatus
include
ActiveModel
::
Model
attr_writer
:health
def
health
@health
||=
HealthCheck
::
Utils
.
process_checks
([
'geo'
])
end
def
healthy?
health
.
blank?
end
def
repositories
@repositories
||=
Project
.
count
end
def
repositories
=
(
value
)
@repositories
=
value
.
to_i
end
def
repositories_synced
@repositories_synced
||=
Geo
::
ProjectRegistry
.
synced
.
count
end
def
repositories_synced
=
(
value
)
@repositories_synced
=
value
.
to_i
end
def
repositories_synced_in_percentage
return
0
if
repositories
.
zero?
(
repositories_synced
.
to_f
/
repositories
.
to_f
)
*
100.0
end
def
repositories_failed
@repositories_failed
||=
Geo
::
ProjectRegistry
.
failed
.
count
end
def
repositories_failed
=
(
value
)
@repositories_failed
=
value
.
to_i
end
end
app/presenters/geo_node_presenter.rb
View file @
b4f88515
class
GeoNodePresenter
<
Gitlab
::
View
::
Presenter
::
Delegated
presents
:geo_node
def
healthy?
health
.
blank?
end
def
health
status
.
health
end
def
repositories
status
.
repositories
.
to_i
end
def
repositories_synced
status
.
repositories_synced
.
to_i
end
def
repositories_synced_in_percentage
return
0
if
repositories
.
zero?
(
repositories_synced
.
to_f
/
repositories
.
to_f
)
*
100.0
end
def
repositories_failed
status
.
repositories_failed
.
to_i
end
delegate
:healthy?
,
:health
,
:repositories
,
:repositories_synced
,
:repositories_synced_in_percentage
,
:repositories_failed
,
to: :status
private
...
...
app/services/geo/node_status_service.rb
View file @
b4f88515
...
...
@@ -6,23 +6,25 @@ module Geo
default_timeout
Gitlab
.
config
.
gitlab
.
geo_status_timeout
def
call
(
status_url
)
response
=
self
.
class
.
get
(
status_url
,
headers:
{
'Content-Type'
=>
'application/json'
,
'PRIVATE-TOKEN'
=>
private_token
})
keys
=
%w(health repositories repositories_synced repositories_failed)
values
=
if
response
.
code
>=
200
&&
response
.
code
<
300
keys
=
GeoNode
::
Status
.
members
.
map
(
&
:to_s
)
response
.
parsed_response
.
values_at
(
*
keys
)
else
[
"Could not connect to Geo node - HTTP Status Code:
#{
response
.
code
}
"
]
begin
response
=
self
.
class
.
get
(
status_url
,
headers:
{
'Content-Type'
=>
'application/json'
,
'PRIVATE-TOKEN'
=>
private_token
})
if
response
.
code
>=
200
&&
response
.
code
<
300
response
.
parsed_response
.
values_at
(
*
keys
)
else
[
"Could not connect to Geo node - HTTP Status Code:
#{
response
.
code
}
"
]
end
rescue
HTTParty
::
Error
,
Errno
::
ECONNREFUSED
=>
e
[
e
.
message
]
end
GeoNode
::
Status
.
new
(
*
values
)
rescue
HTTParty
::
Error
,
Errno
::
ECONNREFUSED
=>
e
GeoNode
::
Status
.
new
(
e
.
message
)
GeoNodeStatus
.
new
(
keys
.
zip
(
values
).
to_h
)
end
private
...
...
lib/api/geo.rb
View file @
b4f88515
...
...
@@ -36,14 +36,7 @@ module API
authenticated_as_admin!
require_node_to_be_secondary!
status
=
GeoNode
::
Status
.
new
(
HealthCheck
::
Utils
.
process_checks
([
'geo'
]),
Project
.
count
,
::
Geo
::
ProjectRegistry
.
synced
.
count
,
::
Geo
::
ProjectRegistry
.
failed
.
count
)
present
status
,
with:
Entities
::
GeoNodeStatus
present
GeoNodeStatus
.
new
,
with:
Entities
::
GeoNodeStatus
end
# Enqueue a batch of IDs of wiki's projects to have their
...
...
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