Skip to content

Commit a5f32c9

Browse files
committed
Refs #38856 - use ForemanTasks chain method
1 parent e41cd68 commit a5f32c9

File tree

2 files changed

+17
-24
lines changed

2 files changed

+17
-24
lines changed

app/services/katello/content_view_manager.rb

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,19 @@ def self.trigger_auto_publish!(request:)
6161
description = _("Auto Publish - Triggered by '%s'") % request.content_view_version.name
6262

6363
# Find running component CV publish tasks for chaining
64-
sibling_task_ids = running_component_publish_task_ids(composite_cv)
64+
sibling_tasks = running_component_publish_tasks(composite_cv)
6565

66-
if sibling_task_ids.any?
66+
if sibling_tasks.any?
6767
# Chain composite publish to wait for running component CVs
68-
ForemanTasks.dynflow.world.chain(
69-
sibling_task_ids,
68+
ForemanTasks.chain(
69+
sibling_tasks,
7070
Actions::Katello::ContentView::Publish,
7171
composite_cv,
7272
description,
7373
auto_published: true,
7474
triggered_by_id: request.content_view_version_id
7575
)
76-
auto_publish_log(request, "task chained to #{sibling_task_ids.size} component tasks")
76+
auto_publish_log(request, "task chained to #{sibling_tasks.size} component tasks")
7777
else
7878
# No component CVs running, publish immediately
7979
ForemanTasks.async_task(Actions::Katello::ContentView::Publish, composite_cv, description, auto_published: true, triggered_by_id: request.content_view_version_id)
@@ -99,18 +99,17 @@ def self.scheduled_composite_publish?(composite_cv)
9999
end
100100
end
101101

102-
def self.running_component_publish_task_ids(composite_cv)
102+
def self.running_component_publish_tasks(composite_cv)
103103
component_cv_ids = composite_cv.components.pluck(:content_view_id)
104104
return [] if component_cv_ids.empty?
105105

106-
tasks = ForemanTasks::Task::DynflowTask
106+
ForemanTasks::Task::DynflowTask
107107
.for_action(::Actions::Katello::ContentView::Publish)
108108
.where(state: ['planning', 'planned', 'running'])
109109
.select do |task|
110110
task_input = task.input
111111
task_input && component_cv_ids.include?(task_input.dig('content_view', 'id'))
112112
end
113-
tasks.map(&:external_id)
114113
end
115114
end
116115
end

test/services/katello/content_view_manager_test.rb

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,9 @@ class ContentViewManagerTest < ActiveSupport::TestCase
3131
cvv = katello_content_view_versions(:composite_view_version_1)
3232

3333
# Create a scheduled publish task for the composite CV
34-
task = ForemanTasks::Task.create!(
35-
type: 'ForemanTasks::Task::DynflowTask',
36-
label: 'Actions::Katello::ContentView::Publish',
37-
state: 'scheduled',
38-
result: 'pending',
39-
external_id: 'test-scheduled-publish-123'
40-
)
34+
task = FactoryBot.create(:dynflow_task, :scheduled,
35+
label: 'Actions::Katello::ContentView::Publish',
36+
external_id: 'test-scheduled-publish-123')
4137

4238
# Mock the delayed plan to return our composite CV as first arg
4339
delayed_plan = mock('delayed_plan')
@@ -55,7 +51,7 @@ class ContentViewManagerTest < ActiveSupport::TestCase
5551

5652
request.expects(:with_lock).yields
5753
request.expects(:destroy!)
58-
Katello::ContentViewManager.expects(:running_component_publish_task_ids).returns([])
54+
Katello::ContentViewManager.expects(:running_component_publish_tasks).returns([])
5955
ForemanTasks.expects(:async_task).with(
6056
::Actions::Katello::ContentView::Publish,
6157
request.content_view,
@@ -69,15 +65,13 @@ class ContentViewManagerTest < ActiveSupport::TestCase
6965

7066
test 'trigger_auto_publish with chaining' do
7167
request = build_stubbed(:katello_content_view_auto_publish_request)
72-
sibling_task_ids = ['task-1', 'task-2']
73-
mock_world = mock('world')
68+
sibling_tasks = [mock('task1'), mock('task2')]
7469

7570
request.expects(:with_lock).yields
7671
request.expects(:destroy!)
77-
Katello::ContentViewManager.expects(:running_component_publish_task_ids).returns(sibling_task_ids)
78-
ForemanTasks.dynflow.expects(:world).returns(mock_world)
79-
mock_world.expects(:chain).with(
80-
sibling_task_ids,
72+
Katello::ContentViewManager.expects(:running_component_publish_tasks).returns(sibling_tasks)
73+
ForemanTasks.expects(:chain).with(
74+
sibling_tasks,
8175
Actions::Katello::ContentView::Publish,
8276
request.content_view,
8377
anything,
@@ -104,7 +98,7 @@ class ContentViewManagerTest < ActiveSupport::TestCase
10498

10599
request.expects(:with_lock).yields
106100
request.expects(:destroy!).never
107-
Katello::ContentViewManager.expects(:running_component_publish_task_ids).returns([])
101+
Katello::ContentViewManager.expects(:running_component_publish_tasks).returns([])
108102
ForemanTasks.expects(:async_task).raises(ForemanTasks::Lock::LockConflict.new(mock, []))
109103

110104
Katello::ContentViewManager.trigger_auto_publish!(request: request)
@@ -114,7 +108,7 @@ class ContentViewManagerTest < ActiveSupport::TestCase
114108
request = build_stubbed(:katello_content_view_auto_publish_request)
115109

116110
request.expects(:with_lock).yields
117-
Katello::ContentViewManager.expects(:running_component_publish_task_ids).returns([])
111+
Katello::ContentViewManager.expects(:running_component_publish_tasks).returns([])
118112
ForemanTasks.expects(:async_task).raises(StandardError)
119113

120114
assert_raises(StandardError) do

0 commit comments

Comments
 (0)