Commit 05ce6a58 authored by Alexandru Croitor's avatar Alexandru Croitor

Track import job id by import state model

We are adding another import state tracking model for
Jira importer and we need to be able to track job id
of the importer. Refactoring this module so that it can
be reused with different project level import state
trackers by making use of the import state model instead
of the project.
parent f8ef6978
......@@ -16,7 +16,7 @@ module Gitlab
return unless start_import
Gitlab::Import::SetAsyncJid.set_jid(project)
Gitlab::Import::SetAsyncJid.set_jid(project.import_state)
Gitlab::JiraImport::Stage::ImportLabelsWorker.perform_async(project.id)
end
......
......@@ -31,7 +31,7 @@ module Gitlab
end
def execute
Gitlab::Import::SetAsyncJid.set_jid(project)
Gitlab::Import::SetAsyncJid.set_jid(project.import_state)
Stage::ImportRepositoryWorker
.perform_async(project.id)
......
......@@ -10,17 +10,18 @@
module Gitlab
module Import
module SetAsyncJid
def self.set_jid(project)
jid = generate_jid(project)
def self.set_jid(import_state)
jid = generate_jid(import_state)
Gitlab::SidekiqStatus
.set(jid, StuckImportJobsWorker::IMPORT_JOBS_EXPIRATION)
project.import_state.update_column(:jid, jid)
import_state.update_column(:jid, jid)
end
def self.generate_jid(project)
"async-import/#{project.id}"
def self.generate_jid(import_state)
importer_name = import_state.class.name.underscore.dasherize
"async-import/#{importer_name}/#{import_state.project_id}"
end
end
end
......
......@@ -18,7 +18,7 @@ module Gitlab
end
def execute
Gitlab::Import::SetAsyncJid.set_jid(project)
Gitlab::Import::SetAsyncJid.set_jid(project.import_state)
schedule_first_tasks_page
true
......
......@@ -27,7 +27,7 @@ describe Gitlab::GithubImport::ParallelImporter do
end
it 'sets the JID in Redis' do
expect(Gitlab::Import::SetAsyncJid).to receive(:set_jid).with(project).and_call_original
expect(Gitlab::Import::SetAsyncJid).to receive(:set_jid).with(project.import_state).and_call_original
importer.execute
end
......
......@@ -8,16 +8,16 @@ describe Gitlab::Import::SetAsyncJid do
it 'sets the JID in Redis' do
expect(Gitlab::SidekiqStatus)
.to receive(:set)
.with("async-import/#{project.id}", StuckImportJobsWorker::IMPORT_JOBS_EXPIRATION)
.with("async-import/project-import-state/#{project.id}", StuckImportJobsWorker::IMPORT_JOBS_EXPIRATION)
.and_call_original
described_class.set_jid(project)
described_class.set_jid(project.import_state)
end
it 'updates the import JID of the project' do
described_class.set_jid(project)
described_class.set_jid(project.import_state)
expect(project.import_state.reload.jid).to eq("async-import/#{project.id}")
expect(project.import_state.reload.jid).to eq("async-import/project-import-state/#{project.id}")
end
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