Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
orhpaned_execution_plans_cleanup.sh
cat <<EOF | foreman-rake console
conf.return_format = ""
batch_size = 1000
persistence = ForemanTasks.dynflow.world.persistence
adapter = persistence.adapter
plans_without_tasks = adapter.db.fetch("select dynflow_execution_plans.uuid from dynflow_execution_plans left join foreman_tasks_tasks on (dynflow_execution_plans.uuid = foreman_tasks_tasks.external_id) where foreman_tasks_tasks.id IS NULL")
deleted = 0
total = plans_without_tasks.count
plans_without_tasks.all.map{|x| x[:uuid]}.in_groups_of(batch_size, false).each do |uuids|
delete_count = persistence.delete_execution_plans({ 'uuid' => uuids }, batch_size)
deleted += delete_count
puts "deleted #{deleted} out of #{total}"
end
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment