2019-04-23 10:27:01 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# The original import JID is the JID of the RepositoryImportWorker job,
|
|
|
|
# which will be removed once that job completes. Reusing that JID could
|
|
|
|
# result in StuckImportJobsWorker marking the job as stuck before we get
|
|
|
|
# to running Stage::ImportRepositoryWorker.
|
|
|
|
#
|
|
|
|
# We work around this by setting the JID to a custom generated one, then
|
|
|
|
# refreshing it in the various stages whenever necessary.
|
|
|
|
module Gitlab
|
|
|
|
module Import
|
|
|
|
module SetAsyncJid
|
2020-04-03 05:09:31 -04:00
|
|
|
def self.set_jid(import_state)
|
|
|
|
jid = generate_jid(import_state)
|
2019-04-23 10:27:01 -04:00
|
|
|
|
|
|
|
Gitlab::SidekiqStatus
|
|
|
|
.set(jid, StuckImportJobsWorker::IMPORT_JOBS_EXPIRATION)
|
|
|
|
|
2020-04-03 05:09:31 -04:00
|
|
|
import_state.update_column(:jid, jid)
|
2019-04-23 10:27:01 -04:00
|
|
|
end
|
|
|
|
|
2020-04-03 05:09:31 -04:00
|
|
|
def self.generate_jid(import_state)
|
|
|
|
importer_name = import_state.class.name.underscore.dasherize
|
|
|
|
"async-import/#{importer_name}/#{import_state.project_id}"
|
2019-04-23 10:27:01 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|