Commit 4805b70c authored by Sean McGivern's avatar Sean McGivern

Merge branch 'georgekoltsov/track-bulk-import-exceptions' into 'master'

Track exceptions when using Bulk Import

See merge request gitlab-org/gitlab!52011
parents dfaf51da abdab263
...@@ -27,6 +27,10 @@ class BulkImportWorker # rubocop:disable Scalability/IdempotentWorker ...@@ -27,6 +27,10 @@ class BulkImportWorker # rubocop:disable Scalability/IdempotentWorker
end end
re_enqueue re_enqueue
rescue => e
Gitlab::ErrorTracking.track_exception(e, bulk_import_id: @bulk_import&.id)
@bulk_import&.fail_op
end end
private private
......
...@@ -18,6 +18,16 @@ module BulkImports ...@@ -18,6 +18,16 @@ module BulkImports
BulkImports::Importers::GroupImporter.new(entity).execute BulkImports::Importers::GroupImporter.new(entity).execute
end 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 end
end end
---
title: Track exceptions when using Bulk Import
merge_request: 52011
author:
type: changed
...@@ -72,6 +72,21 @@ RSpec.describe BulkImportWorker do ...@@ -72,6 +72,21 @@ RSpec.describe BulkImportWorker do
expect(bulk_import.entities.map(&:status_name)).to contain_exactly(:created, :started) expect(bulk_import.entities.map(&:status_name)).to contain_exactly(:created, :started)
end end
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 end
end end
...@@ -24,6 +24,20 @@ RSpec.describe BulkImports::EntityWorker do ...@@ -24,6 +24,20 @@ RSpec.describe BulkImports::EntityWorker do
expect(entity.reload.jid).to eq(jid) expect(entity.reload.jid).to eq(jid)
end 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 end
context 'when started entity does not exist' do 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