Commit 27be1000 authored by Matthias Kaeppler's avatar Matthias Kaeppler

Store correlation ID when starting import

parent 31fbda6f
......@@ -10,6 +10,8 @@ class ProjectImportState < ApplicationRecord
validates :project, presence: true
alias_attribute :correlation_id, :correlation_id_value
state_machine :status, initial: :none do
event :schedule do
transition [:none, :finished, :failed] => :scheduled
......@@ -39,7 +41,11 @@ class ProjectImportState < ApplicationRecord
after_transition [:none, :finished, :failed] => :scheduled do |state, _|
state.run_after_commit do
job_id = project.add_import_job
update(jid: job_id) if job_id
if job_id
correlation_id = Labkit::Correlation::CorrelationId.current_or_new_id
update(jid: job_id, correlation_id_value: correlation_id)
end
end
end
......
......@@ -14,8 +14,8 @@ describe ProjectImportState, type: :model do
end
describe 'Project import job' do
let(:import_state) { create(:import_state, import_url: generate(:url)) }
let(:project) { import_state.project }
let_it_be(:import_state) { create(:import_state, import_url: generate(:url)) }
let_it_be(:project) { import_state.project }
before do
allow_any_instance_of(Gitlab::GitalyClient::RepositoryService).to receive(:import_repository)
......@@ -29,8 +29,16 @@ describe ProjectImportState, type: :model do
it 'imports a project', :sidekiq_might_not_need_inline do
expect(RepositoryImportWorker).to receive(:perform_async).and_call_original
expect { import_state.schedule }.to change { import_state.jid }
expect(import_state.status).to eq('finished')
expect { import_state.schedule }.to change { import_state.status }.from('none').to('finished')
end
it 'records job and correlation IDs', :sidekiq_might_not_need_inline do
allow(Labkit::Correlation::CorrelationId).to receive(:current_or_new_id).and_return('abc')
import_state.schedule
expect(import_state.jid).to be_an_instance_of(String)
expect(import_state.correlation_id).to eq('abc')
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