Commit 7c13836f authored by Robert Speicher's avatar Robert Speicher

Remove `remove_jid` method from ProjectImportState

We now handle this internally on the `ProjectImportState`'s state
machine, so that the Project model doesn't need to know these specific
details of its import state.
parent faa1aa52
...@@ -1773,7 +1773,6 @@ class Project < ApplicationRecord ...@@ -1773,7 +1773,6 @@ class Project < ApplicationRecord
InternalId.flush_records!(project: self) InternalId.flush_records!(project: self)
import_state.finish import_state.finish
import_state.remove_jid
update_project_counter_caches update_project_counter_caches
after_create_default_branch after_create_default_branch
join_pool_repository join_pool_repository
......
...@@ -42,6 +42,14 @@ class ProjectImportState < ApplicationRecord ...@@ -42,6 +42,14 @@ class ProjectImportState < ApplicationRecord
end end
end end
after_transition any => :finished do |state, _|
if state.jid.present?
Gitlab::SidekiqStatus.unset(state.jid)
state.update_column(:jid, nil)
end
end
after_transition started: :finished do |state, _| after_transition started: :finished do |state, _|
project = state.project project = state.project
...@@ -81,14 +89,6 @@ class ProjectImportState < ApplicationRecord ...@@ -81,14 +89,6 @@ class ProjectImportState < ApplicationRecord
status == 'started' && project.import? status == 'started' && project.import?
end end
def remove_jid
return unless jid
Gitlab::SidekiqStatus.unset(jid)
update_column(:jid, nil)
end
# Refreshes the expiration time of the associated import job ID. # Refreshes the expiration time of the associated import job ID.
# #
# This method can be used by asynchronous importers to refresh the status, # This method can be used by asynchronous importers to refresh the status,
......
...@@ -95,30 +95,28 @@ describe ProjectImportState, type: :model do ...@@ -95,30 +95,28 @@ describe ProjectImportState, type: :model do
end end
end end
describe '#remove_jid', :clean_gitlab_redis_cache do describe 'clearing `jid` after finish', :clean_gitlab_redis_cache do
let(:project) { }
context 'without an JID' do context 'without an JID' do
it 'does nothing' do it 'does nothing' do
import_state = create(:import_state) import_state = create(:import_state, :started)
expect(Gitlab::SidekiqStatus) expect(Gitlab::SidekiqStatus)
.not_to receive(:unset) .not_to receive(:unset)
import_state.remove_jid import_state.finish!
end end
end end
context 'with an JID' do context 'with an JID' do
it 'unsets the JID' do it 'unsets the JID' do
import_state = create(:import_state, jid: '123') import_state = create(:import_state, :started, jid: '123')
expect(Gitlab::SidekiqStatus) expect(Gitlab::SidekiqStatus)
.to receive(:unset) .to receive(:unset)
.with('123') .with('123')
.and_call_original .and_call_original
import_state.remove_jid import_state.finish!
expect(import_state.jid).to be_nil expect(import_state.jid).to be_nil
end end
......
...@@ -4335,7 +4335,6 @@ describe Project do ...@@ -4335,7 +4335,6 @@ describe Project do
expect(project.wiki.repository).to receive(:after_import) expect(project.wiki.repository).to receive(:after_import)
expect(import_state).to receive(:finish) expect(import_state).to receive(:finish)
expect(project).to receive(:update_project_counter_caches) expect(project).to receive(:update_project_counter_caches)
expect(import_state).to receive(:remove_jid)
expect(project).to receive(:after_create_default_branch) expect(project).to receive(:after_create_default_branch)
expect(project).to receive(:refresh_markdown_cache!) expect(project).to receive(:refresh_markdown_cache!)
expect(InternalId).to receive(:flush_records!).with(project: project) expect(InternalId).to receive(:flush_records!).with(project: project)
......
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