Skip to content

Commit

Permalink
SAT-30393 - Skip recurring logic tasks if on prem is enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
chris1984 committed Jan 22, 2025
1 parent 21aae16 commit bbed72e
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 21 deletions.
34 changes: 22 additions & 12 deletions lib/foreman_inventory_upload/async/generate_all_reports_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module ForemanInventoryUpload
module Async
class GenerateAllReportsJob < ::Actions::EntryAction
include ::Actions::RecurringAction
include ForemanInventoryUpload::Async::DelayedStart
#include ForemanInventoryUpload::Async::DelayedStart

Check failure on line 5 in lib/foreman_inventory_upload/async/generate_all_reports_job.rb

View workflow job for this annotation

GitHub Actions / Rubocop / Rubocop

Layout/LeadingCommentSpace: Missing space after `#`.

def plan
unless Setting[:allow_auto_inventory_upload]
Expand All @@ -13,20 +13,30 @@ def plan
return
end

after_delay do
organizations = Organization.unscoped.all
# rubocop:disable Style/GuardClause

Check failure on line 16 in lib/foreman_inventory_upload/async/generate_all_reports_job.rb

View workflow job for this annotation

GitHub Actions / Rubocop / Rubocop

Lint/RedundantCopDisableDirective: Unnecessary disabling of `Style/GuardClause`.
if !ForemanRhCloud.with_local_advisor_engine?
after_delay do
organizations = Organization.unscoped.all

organizations.map do |organization|
total_hosts = ForemanInventoryUpload::Generators::Queries.for_org(organization.id, use_batches: false).count
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
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
else
plan_self
end
# rubocop:enable Style/GuardClause
end

def run
output[:status] = _('The scheduled process is disabled because this Foreman is configured with the use_local_advisor_engine option.') if ForemanRhCloud.with_local_advisor_engine?

Check failure on line 39 in lib/foreman_inventory_upload/async/generate_all_reports_job.rb

View workflow job for this annotation

GitHub Actions / Rubocop / Rubocop

Layout/IndentationWidth: Use 2 (not 4) spaces for indentation.
end

def rescue_strategy_for_self
Expand Down
13 changes: 11 additions & 2 deletions lib/insights_cloud/async/insights_scheduled_sync.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,18 @@ def plan
return
end

after_delay do
plan_full_sync
# rubocop:disable Style/GuardClause

Check failure on line 16 in lib/insights_cloud/async/insights_scheduled_sync.rb

View workflow job for this annotation

GitHub Actions / Rubocop / Rubocop

Lint/RedundantCopDisableDirective: Unnecessary disabling of `Style/GuardClause`.
unless ForemanRhCloud.with_local_advisor_engine?
after_delay do
plan_full_sync
end
end
# rubocop:enable Style/GuardClause
plan_self
end

def run
output[:status] = _('The scheduled process is disabled because this Foreman is configured with the use_local_advisor_engine option.') if ForemanRhCloud.with_local_advisor_engine?
end

def plan_full_sync
Expand Down
23 changes: 16 additions & 7 deletions lib/inventory_sync/async/inventory_scheduled_sync.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,32 @@ def plan
return
end

after_delay do
# perform a sequence of sync then delete in parallel for all organizations
concurrence do
Organization.unscoped.each do |org|
sequence do
plan_org_sync(org)
plan_remove_insights_hosts(org.id) if Setting[:allow_auto_insights_mismatch_delete]
# rubocop:disable Style/GuardClause

Check failure on line 16 in lib/inventory_sync/async/inventory_scheduled_sync.rb

View workflow job for this annotation

GitHub Actions / Rubocop / Rubocop

Lint/RedundantCopDisableDirective: Unnecessary disabling of `Style/GuardClause`.
unless ForemanRhCloud.with_local_advisor_engine?
after_delay do
# perform a sequence of sync then delete in parallel for all organizations
concurrence do
Organization.unscoped.each do |org|
sequence do
plan_org_sync(org)
plan_remove_insights_hosts(org.id) if Setting[:allow_auto_insights_mismatch_delete]
end
end
end
end
end
# rubocop:enable Style/GuardClause
plan_self
end

def plan_org_sync(org)
plan_action InventoryFullSync, org
end

def run
output[:status] = _('The scheduled process is disabled because this Foreman is configured with the use_local_advisor_engine option.') if ForemanRhCloud.with_local_advisor_engine?
end

def plan_remove_insights_hosts(org_id)
# plan a remove hosts action with search set to empty (all records)
plan_action(ForemanInventoryUpload::Async::RemoveInsightsHostsJob, '', org_id)
Expand Down

0 comments on commit bbed72e

Please sign in to comment.