Method: Dynflow::PersistenceAdapters::Sequel#delete_execution_plans

Defined in:
lib/dynflow/persistence_adapters/sequel.rb

#delete_execution_plans(filters, batch_size = 1000, backup_dir = nil) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/dynflow/persistence_adapters/sequel.rb', line 95

def delete_execution_plans(filters, batch_size = 1000, backup_dir = nil)
  count = 0
  filter(:execution_plan, table(:execution_plan), filters).each_slice(batch_size) do |plans|
    uuids = plans.map { |p| p.fetch(:uuid) }
    @db.transaction do
      table(:delayed).where(execution_plan_uuid: uuids).delete

      steps = table(:step).where(execution_plan_uuid: uuids)
      backup_to_csv(:step, steps, backup_dir, 'steps.csv') if backup_dir
      steps.delete

      table(:output_chunk).where(execution_plan_uuid: uuids).delete

      actions = table(:action).where(execution_plan_uuid: uuids)
      backup_to_csv(:action, actions, backup_dir, 'actions.csv') if backup_dir
      actions.delete

      execution_plans = table(:execution_plan).where(uuid: uuids)
      backup_to_csv(:execution_plan, execution_plans, backup_dir, 'execution_plans.csv') if backup_dir
      count += execution_plans.delete
    end
  end
  return count
end