Sha256: 7275c37200b52c78d579ee4b7969d0f1492371533cf381d91829606859fb7b84

Contents?: true

Size: 1.47 KB

Versions: 10

Compression:

Stored size: 1.47 KB

Contents

module ForemanInventoryUpload
  module Async
    class GenerateAllReportsJob < ::Actions::EntryAction
      include ::Actions::RecurringAction
      include ForemanInventoryUpload::Async::DelayedStart

      def plan
        unless Setting[:allow_auto_inventory_upload]
          logger.debug(
            'The scheduled process is disabled due to the "allow_auto_inventory_upload"
            setting being set to false.'
          )
          return
        end

        after_delay do
          organizations = Organization.unscoped.all

          organizations.map do |organization|
            total_hosts = ForemanInventoryUpload::Generators::Queries.for_org(organization.id, use_batches: false).count

            if total_hosts <= ForemanInventoryUpload.max_org_size
              disconnected = false
              plan_generate_report(ForemanInventoryUpload.generated_reports_folder, organization, disconnected)
            else
              logger.info("Skipping automatic uploads for organization #{organization.name}, too many hosts (#{total_hosts}/#{ForemanInventoryUpload.max_org_size})")
            end
          end.compact
        end
      end

      def rescue_strategy_for_self
        Dynflow::Action::Rescue::Fail
      end

      def plan_generate_report(folder, organization, disconnected)
        plan_action(ForemanInventoryUpload::Async::GenerateReportJob, folder, organization.id, disconnected)
      end

      def logger
        action_logger
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
foreman_rh_cloud-11.0.3 lib/foreman_inventory_upload/async/generate_all_reports_job.rb
foreman_rh_cloud-9.0.59 lib/foreman_inventory_upload/async/generate_all_reports_job.rb
foreman_rh_cloud-11.0.2 lib/foreman_inventory_upload/async/generate_all_reports_job.rb
foreman_rh_cloud-11.0.1 lib/foreman_inventory_upload/async/generate_all_reports_job.rb
foreman_rh_cloud-11.0.0 lib/foreman_inventory_upload/async/generate_all_reports_job.rb
foreman_rh_cloud-9.0.58 lib/foreman_inventory_upload/async/generate_all_reports_job.rb
foreman_rh_cloud-10.0.2 lib/foreman_inventory_upload/async/generate_all_reports_job.rb
foreman_rh_cloud-9.0.57 lib/foreman_inventory_upload/async/generate_all_reports_job.rb
foreman_rh_cloud-10.0.1 lib/foreman_inventory_upload/async/generate_all_reports_job.rb
foreman_rh_cloud-9.0.56 lib/foreman_inventory_upload/async/generate_all_reports_job.rb