Skip to content

Instantly share code, notes, and snippets.

@mccun934
Created February 13, 2018 13:41
Show Gist options
  • Save mccun934/6711c249ab077dfa8d7d526dcc501a8a to your computer and use it in GitHub Desktop.
Save mccun934/6711c249ab077dfa8d7d526dcc501a8a to your computer and use it in GitHub Desktop.
delete orphan dynflow data
cat <<EOF | foreman-rake console
persistence = ForemanTasks.dynflow.world.persistence
adapter = persistence.adapter
batch_size = 5
total = adapter.db.fetch("select count(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").first[:count]
deleted = 0
puts "about to delete #{total} execution plans"
while (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 LIMIT #{batch_size}").all.map { |x| x[:uuid] }) && !plans_without_tasks.empty?
persistence.delete_execution_plans({ 'uuid' => plans_without_tasks }, batch_size)
deleted += plans_without_tasks.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