@@ -380,19 +380,18 @@ def auto_publish_composites!(component_task_id)
380380 Rails . logger . info ( "Composite CV #{ composite_cv . name } publish running, scheduling event for retry" )
381381 schedule_auto_publish_event ( composite_cv , description )
382382 next
383+ when nil
384+ # No composite publish running or scheduled - trigger one now
385+ sibling_task_ids = find_sibling_component_publish_tasks ( composite_cv , component_task_id )
386+ trigger_composite_publish ( composite_cv , sibling_task_ids , description )
383387 end
384-
385- sibling_task_ids = find_sibling_component_publish_tasks ( composite_cv , component_task_id )
386- trigger_composite_publish ( composite_cv , sibling_task_ids , description )
387388 end
388389 end
389390 end
390391
391392 private
392393
393- # Check if a composite publish task already exists (scheduled or running)
394- # @param composite_cv [Katello::ContentView] The composite content view
395- # @return [Symbol, nil] :scheduled if scheduled, :running if running, nil otherwise
394+ # Returns :scheduled, :running, or nil based on composite CV publish task status
396395 def composite_publish_status ( composite_cv )
397396 # Check scheduled tasks first (they don't have input populated yet)
398397 scheduled_tasks = ForemanTasks ::Task ::DynflowTask
@@ -404,38 +403,33 @@ def composite_publish_status(composite_cv)
404403 end
405404
406405 # Check running tasks (these have input populated)
407- if find_composite_publish_tasks ( composite_cv ) . any?
406+ if find_active_composite_publish_tasks ( composite_cv ) . any?
408407 return :running
409408 end
410409
411410 nil
412411 end
413412
414413 # Schedule an event to retry composite publish after current one finishes
415- # @param composite_cv [Katello::ContentView] The composite content view
416- # @param description [String] Description for the publish task
417414 def schedule_auto_publish_event ( composite_cv , description )
418415 ::Katello ::EventQueue . push_event ( ::Katello ::Events ::AutoPublishCompositeView ::EVENT_TYPE , composite_cv . id ) do |attrs |
419416 attrs [ :metadata ] = { description : description , version_id : self . id }
420417 end
421418 end
422419
423420 # Check if a scheduled task is for the given composite CV by inspecting delayed plan args
424- # @param task [ForemanTasks::Task] The task to check
425- # @param composite_cv [Katello::ContentView] The composite content view
426- # @return [Boolean] true if task is for this composite CV
427421 def scheduled_task_for_composite? ( task , composite_cv )
428422 delayed_plan = ForemanTasks . dynflow . world . persistence . load_delayed_plan ( task . external_id )
423+ return false if delayed_plan . nil?
424+
429425 args = delayed_plan . args
430426 args . first . is_a? ( ::Katello ::ContentView ) && args . first . id == composite_cv . id
431- rescue StandardError
427+ rescue NoMethodError , TypeError , Dynflow ::Error
428+ Rails . logger . error ( "Failed to check scheduled task for composite CV #{ composite_cv . name } : #{ e . message } " )
432429 false
433430 end
434431
435432 # Trigger a composite publish, either immediately or chained to sibling tasks
436- # @param composite_cv [Katello::ContentView] The composite content view
437- # @param sibling_task_ids [Array<String>] Task IDs to wait for
438- # @param description [String] Description for the publish task
439433 def trigger_composite_publish ( composite_cv , sibling_task_ids , description )
440434 if sibling_task_ids . any?
441435 trigger_chained_composite_publish ( composite_cv , sibling_task_ids , description )
@@ -453,7 +447,7 @@ def trigger_composite_publish(composite_cv, sibling_task_ids, description)
453447
454448 # Trigger a chained composite publish that waits for sibling tasks
455449 def trigger_chained_composite_publish ( composite_cv , sibling_task_ids , description )
456- ForemanTasks . chain (
450+ ForemanTasks . dynflow . world . chain (
457451 sibling_task_ids ,
458452 ::Actions ::Katello ::ContentView ::Publish ,
459453 composite_cv ,
@@ -472,10 +466,7 @@ def trigger_immediate_composite_publish(composite_cv, description)
472466 )
473467 end
474468
475- # Find all currently running publish tasks for component CVs that belong to the given composite CV
476- # @param composite_cv [Katello::ContentView] The composite content view
477- # @param current_task_id [String] The execution plan ID of the current component publish task
478- # @return [Array<String>] Array of execution plan IDs for all running component publish tasks
469+ # Find sibling component publish tasks that should be waited for
479470 def find_sibling_component_publish_tasks ( composite_cv , current_task_id )
480471 # Get all component CV IDs for this composite
481472 component_cv_ids = composite_cv . components . pluck ( :content_view_id )
@@ -497,12 +488,8 @@ def find_sibling_component_publish_tasks(composite_cv, current_task_id)
497488 task_ids . reject { |id | id == current_task_id }
498489 end
499490
500- # Find all currently running composite publish tasks for the given composite CV
501- # NOTE: This does NOT check for scheduled tasks - those are handled separately in auto_publish_composites!
502- # by inspecting delayed plan args, since scheduled tasks don't have input populated yet.
503- # @param composite_cv [Katello::ContentView] The composite content view
504- # @return [Array<String>] Array of execution plan IDs for all running composite publish tasks
505- def find_composite_publish_tasks ( composite_cv )
491+ # Find active (planning/planned/running) composite publish tasks (does NOT check scheduled tasks)
492+ def find_active_composite_publish_tasks ( composite_cv )
506493 relevant_tasks = ForemanTasks ::Task ::DynflowTask
507494 . for_action ( ::Actions ::Katello ::ContentView ::Publish )
508495 . where ( state : [ 'planning' , 'planned' , 'running' ] )
0 commit comments