Skip to content

Commit

Permalink
Fixes #37922 - Handle case where proxy no longer exists
Browse files Browse the repository at this point in the history
Fixes e3578d6
  • Loading branch information
adamruzicka committed Oct 17, 2024
1 parent d4abcf5 commit 4efb238
Showing 1 changed file with 3 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
class MigrateSmartProxyIdsToTemplateInvocations < ActiveRecord::Migration[6.0]
def up
proxy_lookup_cache = {}
ForemanTasks::Link.joins(:task)
.where(resource_type: 'SmartProxy', task: { label: 'Actions::RemoteExecution::RunHostJob' })
.where.not(resource_id: nil)
.find_in_batches do |batch|
batch.group_by(&:resource_id).each do |resource_id, links|
proxy_lookup_cache[resource_id] = SmartProxy.where(id: resource_id).exists? unless proxy_lookup_cache.key?(resource_id)
next unless proxy_lookup_cache[resource_id]
template_invocation_ids = ForemanTasks::Link.where(resource_type: 'TemplateInvocation', task_id: links.map(&:task_id)).select(:resource_id)
TemplateInvocation.where(id: template_invocation_ids).update_all(smart_proxy_id: resource_id)
end
Expand Down

0 comments on commit 4efb238

Please sign in to comment.