Commit abdab263 authored by George Koltsov's avatar George Koltsov

Track exceptions when using Bulk Import

- Rescue and track exceptions raised during Bulk
  Import process, in case something goes wrong.
parent 0cbaa670
......@@ -27,6 +27,10 @@ class BulkImportWorker # rubocop:disable Scalability/IdempotentWorker
end
re_enqueue
rescue => e
Gitlab::ErrorTracking.track_exception(e, bulk_import_id: @bulk_import&.id)
@bulk_import&.fail_op
end
private
......
......@@ -18,6 +18,16 @@ module BulkImports
BulkImports::Importers::GroupImporter.new(entity).execute
end
rescue => e
extra = {
bulk_import_id: entity&.bulk_import&.id,
entity_id: entity&.id
}
Gitlab::ErrorTracking.track_exception(e, extra)
entity&.fail_op
end
end
end
---
title: Track exceptions when using Bulk Import
merge_request: 52011
author:
type: changed
......@@ -72,6 +72,21 @@ RSpec.describe BulkImportWorker do
expect(bulk_import.entities.map(&:status_name)).to contain_exactly(:created, :started)
end
end
context 'when exception occurs' do
it 'tracks the exception & marks import as failed' do
bulk_import = create(:bulk_import, :created)
create(:bulk_import_entity, :created, bulk_import: bulk_import)
allow(BulkImports::EntityWorker).to receive(:perform_async).and_raise(StandardError)
expect(Gitlab::ErrorTracking).to receive(:track_exception).with(kind_of(StandardError), bulk_import_id: bulk_import.id)
subject.perform(bulk_import.id)
expect(bulk_import.reload.failed?).to eq(true)
end
end
end
end
end
......@@ -24,6 +24,20 @@ RSpec.describe BulkImports::EntityWorker do
expect(entity.reload.jid).to eq(jid)
end
context 'when exception occurs' do
it 'tracks the exception & marks entity as failed' do
allow(BulkImports::Importers::GroupImporter).to receive(:new) { raise StandardError }
expect(Gitlab::ErrorTracking)
.to receive(:track_exception)
.with(kind_of(StandardError), bulk_import_id: bulk_import.id, entity_id: entity.id)
subject.perform(entity.id)
expect(entity.reload.failed?).to eq(true)
end
end
end
context 'when started entity does not exist' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment