Skip to content

Instantly share code, notes, and snippets.

@gmcculloug
Created June 28, 2019 12:30
Show Gist options
  • Save gmcculloug/c3f846997509dbbf8a00c1faa8f4c1ff to your computer and use it in GitHub Desktop.
Save gmcculloug/c3f846997509dbbf8a00c1faa8f4c1ff to your computer and use it in GitHub Desktop.
$dry_run = true
def clean_automation(klass)
puts "#{$dry_run ? 'DRY RUN' : 'Processing'} #{klass.name}"
klass.where(:state => %w[pending queued]).in_batches.each_with_index do |relation, batch_index|
ids = relation.pluck(:id)
queue_relation = MiqQueue.where(:class_name => klass.name, :instance_id => ids)
puts " Batch #{batch_index} Size #{ids.size} Queue Item Count: #{queue_relation.size}"
if !!$dry_run == false
queue_relation.delete_all
relation.delete_all
end
end
end
start_time = Time.zone.now
clean_automation(AutomationRequest)
clean_automation(AutomationTask)
puts "Completed in #{Time.zone.now - start_time} seconds"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment