Add attachments synced status to each node on Geo nodes page

parent 7a0da750
......@@ -12,6 +12,7 @@ class GeoNodeStatus {
this.$repositoriesSynced = $('.js-repositories-synced', this.$status);
this.$repositoriesFailed = $('.js-repositories-failed', this.$status);
this.$lfsObjectsSynced = $('.js-lfs-objects-synced', this.$status);
this.$attachmentsSynced = $('.js-attachments-synced', this.$status);
this.$health = $('.js-health', this.$status);
this.endpoint = this.$el.data('status-url');
......@@ -31,6 +32,7 @@ class GeoNodeStatus {
this.$repositoriesSynced.html(`${status.repositories_synced_count}/${status.repositories_count} (${status.repositories_synced_in_percentage})`);
this.$repositoriesFailed.html(status.repositories_failed_count);
this.$lfsObjectsSynced.html(`${status.lfs_objects_synced_count}/${status.lfs_objects_count} (${status.lfs_objects_synced_in_percentage})`);
this.$attachmentsSynced.html(`${status.attachments_synced_count}/${status.attachments_count} (${status.attachments_synced_in_percentage})`);
this.$health.html(status.health);
this.$status.show();
......
......@@ -60,6 +60,26 @@ class GeoNodeStatus
sync_percentage(lfs_objects_count, lfs_objects_synced_count)
end
def attachments_count
@attachments_count ||= Upload.count
end
def attachments_count=(value)
@attachments_count = value.to_i
end
def attachments_synced_count
@attachments_synced_count ||= Geo::FileRegistry.where(file_type: [:attachment, :avatar, :file]).count
end
def attachments_synced_count=(value)
@attachments_synced_count = value.to_i
end
def attachments_synced_in_percentage
sync_percentage(attachments_count, attachments_synced_count)
end
private
def sync_percentage(total, synced)
......
......@@ -8,6 +8,12 @@ class GeoNodeStatusEntity < Grape::Entity
node.healthy? ? 'No Health Problems Detected' : node.health
end
expose :attachments_count
expose :attachments_synced_count
expose :attachments_synced_in_percentage do |node|
number_to_percentage(node.attachments_synced_in_percentage, precision: 2)
end
expose :lfs_objects_count
expose :lfs_objects_synced_count
expose :lfs_objects_synced_in_percentage do |node|
......
......@@ -10,6 +10,8 @@ module Geo
repositories_failed_count
lfs_objects_count
lfs_objects_synced_count
attachments_count
attachments_synced_count
).freeze
def call(geo_node)
......
......@@ -37,6 +37,10 @@
%span.help-block
LFS objects synced:
%span.js-lfs-objects-synced
%p
%span.help-block
Attachments synced:
%span.js-attachments-synced
%p
%span.help-block.js-health
......
......@@ -213,6 +213,8 @@ describe Admin::GeoNodesController do
GeoNodeStatus.new(
id: 1,
health: nil,
attachments_count: 329,
attachments_synced_count: 141,
lfs_objects_count: 256,
lfs_objects_synced_count: 123,
repositories_count: 10,
......
......@@ -16,6 +16,9 @@
"id": { "type": "integer" },
"healthy": { "type": "boolean" },
"health": { "type": "string" },
"attachments_count": { "type": "integer" },
"attachments_synced_count": { "type": "integer" },
"attachments_synced_in_percentage": { "type": "string" },
"lfs_objects_count": { "type": "integer" },
"lfs_objects_synced_count": { "type": "integer" },
"lfs_objects_synced_in_percentage": { "type": "string" },
......
......@@ -31,6 +31,22 @@ describe GeoNodeStatus, model: true do
end
end
describe '#attachments_synced_in_percentage' do
it 'returns 0 when no objects are available' do
subject.attachments_count = 0
subject.attachments_synced_count = 0
expect(subject.attachments_synced_in_percentage).to eq(0)
end
it 'returns the right percentage' do
subject.attachments_count = 4
subject.attachments_synced_count = 1
expect(subject.attachments_synced_in_percentage).to be_within(0.0001).of(25)
end
end
describe '#lfs_objects_synced_in_percentage' do
it 'returns 0 when no objects are available' do
subject.lfs_objects_count = 0
......@@ -65,6 +81,8 @@ describe GeoNodeStatus, model: true do
context 'when no values are available' do
it 'returns 0 for each attribute' do
subject.attachments_count = nil
subject.attachments_synced_count = nil
subject.lfs_objects_count = nil
subject.lfs_objects_synced_count = nil
subject.repositories_count = nil
......@@ -78,6 +96,9 @@ describe GeoNodeStatus, model: true do
expect(subject.lfs_objects_count).to be_zero
expect(subject.lfs_objects_synced_count).to be_zero
expect(subject.lfs_objects_synced_in_percentage).to be_zero
expect(subject.attachments_count).to be_zero
expect(subject.attachments_synced_count).to be_zero
expect(subject.attachments_synced_in_percentage).to be_zero
end
end
end
......@@ -5,6 +5,8 @@ describe GeoNodeStatusEntity do
GeoNodeStatus.new(
id: 1,
health: nil,
attachments_count: 329,
attachments_synced_count: 141,
lfs_objects_count: 256,
lfs_objects_synced_count: 123,
repositories_count: 10,
......@@ -25,6 +27,9 @@ describe GeoNodeStatusEntity do
it { is_expected.to have_key(:id) }
it { is_expected.to have_key(:healthy) }
it { is_expected.to have_key(:health) }
it { is_expected.to have_key(:attachments_count) }
it { is_expected.to have_key(:attachments_synced_count) }
it { is_expected.to have_key(:attachments_synced_in_percentage) }
it { is_expected.to have_key(:lfs_objects_count) }
it { is_expected.to have_key(:lfs_objects_synced_count) }
it { is_expected.to have_key(:lfs_objects_synced_in_percentage) }
......@@ -73,6 +78,12 @@ describe GeoNodeStatusEntity do
end
end
describe '#attachments_synced_in_percentage' do
it 'formats as percentage' do
expect(subject[:attachments_synced_in_percentage]).to eq '42.86%'
end
end
describe '#lfs_objects_synced_in_percentage' do
it 'formats as percentage' do
expect(subject[:lfs_objects_synced_in_percentage]).to eq '48.05%'
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment