Class: Katello::ContentViewManager
- Inherits:
-
Object
- Object
- Katello::ContentViewManager
- Defined in:
- app/services/katello/content_view_manager.rb
Class Method Summary collapse
- .add_version_to_environment(content_view_version:, environment:) ⇒ Object
- .auto_publish_log(request, message) ⇒ Object
- .content_view_locks(content_view:) ⇒ Object
- .create_candlepin_environment(content_view_environment:) ⇒ Object
- .request_auto_publish(content_view:, content_view_version:) ⇒ Object
- .running_component_publish_tasks(composite_cv) ⇒ Object
- .scheduled_composite_publish?(composite_cv) ⇒ Boolean
- .trigger_auto_publish!(request:) ⇒ Object
Class Method Details
.add_version_to_environment(content_view_version:, environment:) ⇒ Object
3 4 5 6 7 8 9 10 11 |
# File 'app/services/katello/content_view_manager.rb', line 3 def self.add_version_to_environment(content_view_version:, environment:) content_view = content_view_version.content_view if (cve = content_view.content_view_environment(environment)) content_view_version.content_view_environments << cve else cve = content_view.add_environment(environment, content_view_version) end cve end |
.auto_publish_log(request, message) ⇒ Object
41 42 43 44 |
# File 'app/services/katello/content_view_manager.rb', line 41 def self.auto_publish_log(request, ) logged_request = Katello::Logging.join_parts(request.try(:slice, :id, :content_view_id, :content_view_version_id, :created_at)) Rails.logger.info "[auto publish] #{} #{logged_request}" end |
.content_view_locks(content_view:) ⇒ Object
46 47 48 49 50 |
# File 'app/services/katello/content_view_manager.rb', line 46 def self.content_view_locks(content_view:) ForemanTasks::Lock.where( resource_id: content_view.id, resource_type: ::Katello::ContentView.to_s) end |
.create_candlepin_environment(content_view_environment:) ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'app/services/katello/content_view_manager.rb', line 13 def self.create_candlepin_environment(content_view_environment:) unless content_view_environment.exists_in_candlepin? ::Katello::Resources::Candlepin::Environment.create( content_view_environment.content_view.organization.label, content_view_environment.cp_id, content_view_environment.label, content_view_environment.content_view.description.try(:truncate, 255) ) end end |
.request_auto_publish(content_view:, content_view_version:) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'app/services/katello/content_view_manager.rb', line 24 def self.request_auto_publish(content_view:, content_view_version:) if scheduled_composite_publish?(content_view) auto_publish_log(nil, "composite publish already scheduled for ID #{content_view.id}, skipping") return end request = content_view.create_auto_publish_request!( content_view_version: content_view_version ) auto_publish_log(request, "request created") request rescue ActiveRecord::RecordNotUnique auto_publish_log(content_view.auto_publish_request, "request exists") content_view.auto_publish_request end |
.running_component_publish_tasks(composite_cv) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'app/services/katello/content_view_manager.rb', line 102 def self.running_component_publish_tasks(composite_cv) component_cv_ids = composite_cv.components.pluck(:content_view_id) return [] if component_cv_ids.empty? ForemanTasks::Task::DynflowTask .for_action(::Actions::Katello::ContentView::Publish) .where(state: ['planning', 'planned', 'running']) .select do |task| task_input = task.input task_input && component_cv_ids.include?(task_input.dig('content_view', 'id')) end end |
.scheduled_composite_publish?(composite_cv) ⇒ Boolean
91 92 93 94 95 96 97 98 99 100 |
# File 'app/services/katello/content_view_manager.rb', line 91 def self.scheduled_composite_publish?(composite_cv) ForemanTasks::Task::DynflowTask .for_action(::Actions::Katello::ContentView::Publish) .where(state: 'scheduled') .any? do |task| delayed_plan = ForemanTasks.dynflow.world.persistence.load_delayed_plan(task.external_id) args = delayed_plan.args args.first.is_a?(::Katello::ContentView) && args.first.id == composite_cv.id end end |
.trigger_auto_publish!(request:) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'app/services/katello/content_view_manager.rb', line 52 def self.trigger_auto_publish!(request:) request.with_lock do composite_cv = request.content_view if content_view_locks(content_view: composite_cv).any? auto_publish_log(request, "locks found") return end description = _("Auto Publish - Triggered by '%s'") % request.content_view_version.name # Find running component CV publish tasks for chaining sibling_tasks = running_component_publish_tasks(composite_cv) if sibling_tasks.any? # Chain composite publish to wait for running component CVs ForemanTasks.chain( sibling_tasks, Actions::Katello::ContentView::Publish, composite_cv, description, auto_published: true, triggered_by_id: request.content_view_version_id ) auto_publish_log(request, "task chained to #{sibling_tasks.size} component tasks") else # No component CVs running, publish immediately ForemanTasks.async_task(Actions::Katello::ContentView::Publish, composite_cv, description, auto_published: true, triggered_by_id: request.content_view_version_id) auto_publish_log(request, "task triggered") end request.destroy! rescue ForemanTasks::Lock::LockConflict => e auto_publish_log(request, e) auto_publish_log(request, "lock conflict") end rescue ActiveRecord::RecordNotFound auto_publish_log(request, "request gone") end |