Commit e809094d authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch 'georgekoltsov/update-relation-export-service' into 'master'

Update RelationExportService to not perform export if relation is recently exported

See merge request gitlab-org/gitlab!84207
parents 469ed24f 662e1bd7
......@@ -4,6 +4,8 @@ module BulkImports
class RelationExportService
include Gitlab::ImportExport::CommandLineUtil
EXISTING_EXPORT_TTL = 3.minutes
def initialize(user, portable, relation, jid)
@user = user
@portable = portable
......@@ -31,6 +33,9 @@ module BulkImports
validate_user_permissions!
export = portable.bulk_import_exports.safe_find_or_create_by!(relation: relation)
return export if export.finished? && export.updated_at > EXISTING_EXPORT_TTL.ago
export.update!(status_event: 'start', jid: jid)
yield export
......
......@@ -3,12 +3,12 @@
module BulkImports
class RelationExportWorker
include ApplicationWorker
data_consistency :always
include ExceptionBacktrace
idempotent!
deduplicate :until_executed
loggable_arguments 2, 3
data_consistency :always
feature_category :importers
sidekiq_options status_expiration: StuckExportJobsWorker::EXPORT_JOBS_EXPIRATION
......
......@@ -88,6 +88,18 @@ RSpec.describe BulkImports::RelationExportService do
subject.execute
end
context 'when export is recently finished' do
it 'returns recently finished export instead of re-exporting' do
updated_at = 5.seconds.ago
export.update!(status: 1, updated_at: updated_at)
expect { subject.execute }.not_to change { export.updated_at }
expect(export.status).to eq(1)
expect(export.updated_at).to eq(updated_at)
end
end
end
context 'when exception occurs during export' 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