Sha256: e68c11ba891cc78dae91eb6ddc665a4d0a3986636862d923465eb98066492c33

Contents?: true

Size: 1.21 KB

Versions: 92

Compression:

Stored size: 1.21 KB

Contents

module Actions
  module Middleware
    class ProxyBatchTriggering < ::Dynflow::Middleware
      # If the event could result into sub tasks being planned, check if there are any RemoteTasks
      # to trigger after the event is processed
      #
      # The ProxyAction needs to be planned with `:use_batch_triggering => true` to activate the feature
      def run(event = nil)
        pass event
      ensure
        trigger_remote_tasks if event.nil? || event.is_a?(Dynflow::Action::WithBulkSubPlans::PlanNextBatch)
      end

      def trigger_remote_tasks
        # Find the tasks in batches, order them by proxy_url so we get all tasks
        # to a certain proxy "close to each other"
        remote_tasks.pending.order(:proxy_url, :id).find_in_batches(:batch_size => batch_size) do |batch|
          # Group the tasks by operation, in theory there should be only one operation
          batch.group_by(&:operation).each do |operation, group|
            ForemanTasks::RemoteTask.batch_trigger(operation, group)
          end
        end
      end

      def remote_tasks
        action.task.remote_sub_tasks
      end

      private

      def batch_size
        Setting['foreman_tasks_proxy_batch_size']
      end
    end
  end
end

Version data entries

92 entries across 92 versions & 1 rubygems

Version Path
foreman-tasks-8.1.2 app/lib/actions/middleware/proxy_batch_triggering.rb
foreman-tasks-8.1.1 app/lib/actions/middleware/proxy_batch_triggering.rb
foreman-tasks-8.1.0 app/lib/actions/middleware/proxy_batch_triggering.rb
foreman-tasks-8.0.2 app/lib/actions/middleware/proxy_batch_triggering.rb
foreman-tasks-8.0.1 app/lib/actions/middleware/proxy_batch_triggering.rb
foreman-tasks-8.0.0 app/lib/actions/middleware/proxy_batch_triggering.rb
foreman-tasks-7.2.1 app/lib/actions/middleware/proxy_batch_triggering.rb
foreman-tasks-7.1.1 app/lib/actions/middleware/proxy_batch_triggering.rb
foreman-tasks-7.2.0 app/lib/actions/middleware/proxy_batch_triggering.rb
foreman-tasks-7.1.0 app/lib/actions/middleware/proxy_batch_triggering.rb
foreman-tasks-6.0.3 app/lib/actions/middleware/proxy_batch_triggering.rb
foreman-tasks-7.0.0 app/lib/actions/middleware/proxy_batch_triggering.rb
foreman-tasks-6.0.2 app/lib/actions/middleware/proxy_batch_triggering.rb
foreman-tasks-4.1.6 app/lib/actions/middleware/proxy_batch_triggering.rb
foreman-tasks-5.2.3 app/lib/actions/middleware/proxy_batch_triggering.rb
foreman-tasks-6.0.1 app/lib/actions/middleware/proxy_batch_triggering.rb
foreman-tasks-5.2.2 app/lib/actions/middleware/proxy_batch_triggering.rb
foreman-tasks-6.0.0 app/lib/actions/middleware/proxy_batch_triggering.rb
foreman-tasks-5.2.1 app/lib/actions/middleware/proxy_batch_triggering.rb
foreman-tasks-5.3.0 app/lib/actions/middleware/proxy_batch_triggering.rb