Skip to content

Commit

Permalink
Rescue when trying to delete a dump associated with an IndexManager (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
maxkadel authored May 30, 2024
1 parent 8fdf802 commit 63241db
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/jobs/delete_events_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ def perform(dump_type:, older_than:)
.where(start: ..older_than)
.map(&:id)
Event.destroy(event_ids)
rescue ActiveRecord::InvalidForeignKey => error
Rails.logger.warn("Likely tried to delete a dump that is either the 'dump_in_progress' or 'last_dump_completed' for an index manager.\n Error message: #{error.message}")
end
end
23 changes: 23 additions & 0 deletions spec/jobs/delete_events_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,29 @@
expect(Dir.empty?(File.join(copy_path, partner_recap_daily_event.id.to_s))).to be false
end
end

context "for full dump events that are still associated with an index manager" do
let!(:index_manager) { FactoryBot.create(:index_manager, dump_in_progress: old_event.dump) }
let(:old_event) do
FactoryBot.create(:full_dump_event).tap do |e|
tmp_dump_files(e)
e.start = 6.months.ago - 1.day
e.save
end
end

it 'does not raise an error' do
expect do
described_class.perform_now(dump_type: :full_dump, older_than: 2.months.ago)
end.not_to raise_error
end

it 'logs a warning about the failed deletion' do
allow(Rails.logger).to receive(:warn)
described_class.perform_now(dump_type: :full_dump, older_than: 2.months.ago)
expect(Rails.logger).to have_received(:warn).with(/update or delete on table/)
end
end
end
end

Expand Down

0 comments on commit 63241db

Please sign in to comment.