Sha256: c7ccb3f52f839dc13a6a922f9868815e71487e6dfbcf7f50fdf9ba57117ea0c2

Contents?: true

Size: 1.39 KB

Versions: 13

Compression:

Stored size: 1.39 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
              plan_generate_report(ForemanInventoryUpload.generated_reports_folder, organization)
            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)
        plan_action(ForemanInventoryUpload::Async::GenerateReportJob, folder, organization.id)
      end

      def logger
        action_logger
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
foreman_rh_cloud-9.0.51 lib/foreman_inventory_upload/async/generate_all_reports_job.rb
foreman_rh_cloud-8.0.51 lib/foreman_inventory_upload/async/generate_all_reports_job.rb
foreman_rh_cloud-7.0.48 lib/foreman_inventory_upload/async/generate_all_reports_job.rb
foreman_rh_cloud-7.0.47 lib/foreman_inventory_upload/async/generate_all_reports_job.rb
foreman_rh_cloud-8.0.50 lib/foreman_inventory_upload/async/generate_all_reports_job.rb
foreman_rh_cloud-8.0.49 lib/foreman_inventory_upload/async/generate_all_reports_job.rb
foreman_rh_cloud-8.0.48 lib/foreman_inventory_upload/async/generate_all_reports_job.rb
foreman_rh_cloud-8.0.47 lib/foreman_inventory_upload/async/generate_all_reports_job.rb
foreman_rh_cloud-8.0.46 lib/foreman_inventory_upload/async/generate_all_reports_job.rb
foreman_rh_cloud-6.0.45 lib/foreman_inventory_upload/async/generate_all_reports_job.rb
foreman_rh_cloud-7.0.46 lib/foreman_inventory_upload/async/generate_all_reports_job.rb
foreman_rh_cloud-7.0.45 lib/foreman_inventory_upload/async/generate_all_reports_job.rb
foreman_rh_cloud-6.0.44 lib/foreman_inventory_upload/async/generate_all_reports_job.rb