Commit 816aa6fa authored by Mark Chao's avatar Mark Chao

Merge branch '352985-2-other-bulk-import-class-stale-cleanup' into 'master'

Mark Import trackers as timed out with entities

See merge request gitlab-org/gitlab!83530
parents 4bfa8a0e 5e23c718
......@@ -46,6 +46,7 @@ class BulkImports::Tracker < ApplicationRecord
state :started, value: 1
state :finished, value: 2
state :enqueued, value: 3
state :timeout, value: 4
state :failed, value: -1
state :skipped, value: -2
......@@ -76,5 +77,9 @@ class BulkImports::Tracker < ApplicationRecord
event :fail_op do
transition any => :failed
end
event :cleanup_stale do
transition [:created, :started] => :timeout
end
end
end
......@@ -16,8 +16,15 @@ module BulkImports
BulkImport.stale.find_each do |import|
import.cleanup_stale
end
BulkImports::Entity.stale.find_each do |import|
import.cleanup_stale
BulkImports::Entity.includes(:trackers).stale.find_each do |import| # rubocop: disable CodeReuse/ActiveRecord
ApplicationRecord.transaction do
import.cleanup_stale
import.trackers.find_each do |tracker|
tracker.cleanup_stale
end
end
end
end
end
......
......@@ -9,18 +9,23 @@ RSpec.describe BulkImports::StuckImportWorker do
let_it_be(:stale_started_bulk_import) { create(:bulk_import, :started, created_at: 3.days.ago) }
let_it_be(:stale_created_bulk_import_entity) { create(:bulk_import_entity, :created, created_at: 3.days.ago) }
let_it_be(:stale_started_bulk_import_entity) { create(:bulk_import_entity, :started, created_at: 3.days.ago) }
let_it_be(:started_bulk_import_tracker) { create(:bulk_import_tracker, :started, entity: stale_started_bulk_import_entity) }
subject { described_class.new.perform }
describe 'perform' do
it 'updates the status of bulk imports to timeout' do
expect { subject }.to change { stale_created_bulk_import.reload.status }.from(0).to(3)
.and change { stale_started_bulk_import.reload.status }.from(1).to(3)
expect { subject }.to change { stale_created_bulk_import.reload.status_name }.from(:created).to(:timeout)
.and change { stale_started_bulk_import.reload.status_name }.from(:started).to(:timeout)
end
it 'updates the status of bulk import entities to timeout' do
expect { subject }.to change { stale_created_bulk_import_entity.reload.status }.from(0).to(3)
.and change { stale_started_bulk_import_entity.reload.status }.from(1).to(3)
expect { subject }.to change { stale_created_bulk_import_entity.reload.status_name }.from(:created).to(:timeout)
.and change { stale_started_bulk_import_entity.reload.status_name }.from(:started).to(:timeout)
end
it 'updates the status of stale entities trackers to timeout' do
expect { subject }.to change { started_bulk_import_tracker.reload.status_name }.from(:started).to(:timeout)
end
it 'does not update the status of non-stale records' 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