-
Notifications
You must be signed in to change notification settings - Fork 27
/
generate_all_reports_job.rb
44 lines (37 loc) · 1.39 KB
/
generate_all_reports_job.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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