From 75592c9bc8a6409ab5b338f47ee0d798a245521f Mon Sep 17 00:00:00 2001 From: Samir Jha Date: Thu, 26 Oct 2023 20:17:26 +0000 Subject: [PATCH] Fixes #36852 - Allow fetching capsule sync task per env --- .../concerns/smart_proxy_extensions.rb | 19 +++++++++++++++++++ .../v2/capsule_content/sync_status.json.rabl | 11 +++++++++++ .../SmartProxy/SmartProxyExpandableTable.js | 7 +++---- 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/app/models/katello/concerns/smart_proxy_extensions.rb b/app/models/katello/concerns/smart_proxy_extensions.rb index c6c2e218f8e..ead5b13776b 100644 --- a/app/models/katello/concerns/smart_proxy_extensions.rb +++ b/app/models/katello/concerns/smart_proxy_extensions.rb @@ -414,6 +414,14 @@ def available_lifecycle_environments(organization_id = nil) scope end + def last_complete_sync_task + ForemanTasks::Task.for_resource(self).where(:label => 'Actions::Katello::CapsuleContent::Sync').order(started_at: :desc).detect do |task| + task.input.with_indifferent_access[:options][:environment_id].nil? && + task.input.with_indifferent_access[:options][:content_view_id].nil? && + task.input.with_indifferent_access[:options][:repository_id].nil? + end + end + def sync_tasks ForemanTasks::Task.for_resource(self).where(:label => 'Actions::Katello::CapsuleContent::Sync') end @@ -442,6 +450,17 @@ def environment_syncable?(env) last_sync_time.nil? || env.content_view_environments.where('updated_at > ?', last_sync_time).any? end + def last_env_sync_task(env) + last_env_sync_task = sync_tasks.order(ended_at: :desc).detect { |task| task.input.with_indifferent_access[:options][:environment_id] == env.id } + if (last_complete_sync_task&.ended_at && last_env_sync_task&.ended_at) + return last_complete_sync_task.ended_at > last_env_sync_task.ended_at ? last_complete_sync_task : last_env_sync_task + elsif last_env_sync_task + return last_env_sync_task + elsif last_complete_sync_task + return last_complete_sync_task + end + end + def cancel_sync active_sync_tasks.map(&:cancel) end diff --git a/app/views/katello/api/v2/capsule_content/sync_status.json.rabl b/app/views/katello/api/v2/capsule_content/sync_status.json.rabl index d4791c8cd27..465b775e0da 100644 --- a/app/views/katello/api/v2/capsule_content/sync_status.json.rabl +++ b/app/views/katello/api/v2/capsule_content/sync_status.json.rabl @@ -35,6 +35,17 @@ child @lifecycle_environments => :lifecycle_environments do @capsule.environment_syncable?(env) end + node :last_sync do |env| + last_env_sync_task = @capsule.last_env_sync_task(env) + attributes = { + :id => last_env_sync_task&.id, + :started_at => last_env_sync_task&.started_at, + :result => last_env_sync_task&.result, + :last_sync_words => last_env_sync_task.try(:started_at) ? time_ago_in_words(Time.parse(last_env_sync_task.started_at.to_s)) : nil + } + attributes + end + if @capsule.has_feature?(SmartProxy::PULP_NODE_FEATURE) || @capsule.has_feature?(SmartProxy::PULP3_FEATURE) node :counts do |env| { diff --git a/webpack/scenes/SmartProxy/SmartProxyExpandableTable.js b/webpack/scenes/SmartProxy/SmartProxyExpandableTable.js index 6da2412b3a2..155a01dbbbc 100644 --- a/webpack/scenes/SmartProxy/SmartProxyExpandableTable.js +++ b/webpack/scenes/SmartProxy/SmartProxyExpandableTable.js @@ -25,8 +25,7 @@ const SmartProxyExpandableTable = ({ smartProxyId, organizationId }) => { const dispatch = useDispatch(); let metadata = {}; const { - lifecycle_environments: results, last_sync_task: lastTask, last_sync_words: lastSyncWords, - content_counts: contentCounts, + lifecycle_environments: results, content_counts: contentCounts, } = response; if (results) { metadata = { total: results.length, subtotal: results.length }; @@ -89,7 +88,7 @@ const SmartProxyExpandableTable = ({ smartProxyId, organizationId }) => { { results?.map((env, rowIndex) => { const { - id, content_views: contentViews, + id, content_views: contentViews, last_sync: lastSync, } = env; const isExpanded = tableRowIsExpanded(id); return ( @@ -106,7 +105,7 @@ const SmartProxyExpandableTable = ({ smartProxyId, organizationId }) => { }} /> - +