Class: ForemanInventoryUpload::Async::GenerateAllReportsJob

Inherits:
Actions::EntryAction
  • Object
show all
Includes:
Actions::RecurringAction, DelayedStart
Defined in:
lib/foreman_inventory_upload/async/generate_all_reports_job.rb

Constant Summary

Constants included from DelayedStart

DelayedStart::START_WINDOW

Instance Method Summary collapse

Methods included from DelayedStart

#after_delay, #humanized_name

Instance Method Details

#loggerObject



40
41
42
# File 'lib/foreman_inventory_upload/async/generate_all_reports_job.rb', line 40

def logger
  action_logger
end

#planObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/foreman_inventory_upload/async/generate_all_reports_job.rb', line 7

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

#plan_generate_report(folder, organization, disconnected) ⇒ Object



36
37
38
# File 'lib/foreman_inventory_upload/async/generate_all_reports_job.rb', line 36

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

#rescue_strategy_for_selfObject



32
33
34
# File 'lib/foreman_inventory_upload/async/generate_all_reports_job.rb', line 32

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