Skip to content

Commit

Permalink
Fixes #36852 - Allow fetching capsule sync task per env
Browse files Browse the repository at this point in the history
  • Loading branch information
sjha4 committed Oct 26, 2023
1 parent 586f2fe commit bf5c415
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
19 changes: 19 additions & 0 deletions app/models/katello/concerns/smart_proxy_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 && last_env_sync_task)
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
Expand Down
11 changes: 11 additions & 0 deletions app/views/katello/api/v2/capsule_content/sync_status.json.rabl
Original file line number Diff line number Diff line change
Expand Up @@ -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|
{
Expand Down
7 changes: 3 additions & 4 deletions webpack/scenes/SmartProxy/SmartProxyExpandableTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down Expand Up @@ -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 (
Expand All @@ -106,7 +105,7 @@ const SmartProxyExpandableTable = ({ smartProxyId, organizationId }) => {
}}
/>
<Td><ComponentEnvironments environments={[env]} /></Td>
<Td><LastSync lastSync={lastTask} lastSyncWords={lastSyncWords} emptyMessage="N/A" /></Td>
<Td><LastSync lastSync={lastSync} lastSyncWords={lastSync?.last_sync_words} emptyMessage="N/A" /></Td>
<Td
key={`rowActions-${id}`}
actions={{
Expand Down

0 comments on commit bf5c415

Please sign in to comment.