Commit 56ecf54e authored by Mayra Cabrera's avatar Mayra Cabrera

Merge branch '327405-fix-setting-of-status-for-background-migration-jobs' into 'master'

Ensure that migration job status is updated

See merge request gitlab-org/gitlab!59864
parents eb756336 38d06107
......@@ -19,10 +19,10 @@ module Gitlab
execute_batch(batch_tracking_record)
batch_tracking_record.status = :succeeded
rescue => e
rescue Exception # rubocop:disable Lint/RescueException
batch_tracking_record.status = :failed
raise e
raise
ensure
finish_tracking_execution(batch_tracking_record)
track_prometheus_metrics(batch_tracking_record)
......
......@@ -112,13 +112,14 @@ RSpec.describe Gitlab::Database::BackgroundMigration::BatchedMigrationWrapper, '
end
context 'when the migration job raises an error' do
it 'marks the tracking record as failed before raising the error' do
shared_examples 'an error is raised' do |error_class|
it 'marks the tracking record as failed' do
expect(job_instance).to receive(:perform)
.with(1, 10, 'events', 'id', 1, 'id', 'other_id')
.and_raise(RuntimeError, 'Something broke!')
.and_raise(error_class)
freeze_time do
expect { subject }.to raise_error(RuntimeError, 'Something broke!')
expect { subject }.to raise_error(error_class)
reloaded_job_record = job_record.reload
......@@ -127,4 +128,8 @@ RSpec.describe Gitlab::Database::BackgroundMigration::BatchedMigrationWrapper, '
end
end
end
it_behaves_like 'an error is raised', RuntimeError.new('Something broke!')
it_behaves_like 'an error is raised', SignalException.new('SIGTERM')
end
end
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