Skip to content

Instantly share code, notes, and snippets.

@iNecas
Created June 19, 2018 20:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iNecas/04fdacab137cb7c619ee6cc3a0b0c860 to your computer and use it in GitHub Desktop.
Save iNecas/04fdacab137cb7c619ee6cc3a0b0c860 to your computer and use it in GitHub Desktop.
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