2017-10-13 16:50:36 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module GithubImport
|
|
|
|
class RefreshImportJidWorker
|
2017-11-28 16:08:30 +00:00
|
|
|
include ApplicationWorker
|
2017-10-13 16:50:36 +00:00
|
|
|
include GithubImport::Queue
|
|
|
|
|
|
|
|
# The interval to schedule new instances of this job at.
|
|
|
|
INTERVAL = 1.minute.to_i
|
|
|
|
|
|
|
|
def self.perform_in_the_future(*args)
|
|
|
|
perform_in(INTERVAL, *args)
|
|
|
|
end
|
|
|
|
|
|
|
|
# project_id - The ID of the project that is being imported.
|
|
|
|
# check_job_id - The ID of the job for which to check the status.
|
|
|
|
def perform(project_id, check_job_id)
|
2018-11-27 09:41:27 +00:00
|
|
|
import_state = find_import_state(project_id)
|
|
|
|
return unless import_state
|
2017-10-13 16:50:36 +00:00
|
|
|
|
|
|
|
if SidekiqStatus.running?(check_job_id)
|
|
|
|
# As long as the repository is being cloned we want to keep refreshing
|
|
|
|
# the import JID status.
|
2018-11-27 09:41:27 +00:00
|
|
|
import_state.refresh_jid_expiration
|
2017-10-13 16:50:36 +00:00
|
|
|
self.class.perform_in_the_future(project_id, check_job_id)
|
|
|
|
end
|
|
|
|
|
|
|
|
# If the job is no longer running there's nothing else we need to do. If
|
|
|
|
# the clone job completed successfully it will have scheduled the next
|
|
|
|
# stage, if it died there's nothing we can do anyway.
|
|
|
|
end
|
|
|
|
|
2018-08-27 15:31:01 +00:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2018-11-27 09:41:27 +00:00
|
|
|
def find_import_state(project_id)
|
|
|
|
ProjectImportState.select(:jid)
|
|
|
|
.with_status(:started)
|
|
|
|
.find_by(project_id: project_id)
|
2017-10-13 16:50:36 +00:00
|
|
|
end
|
2018-08-27 15:31:01 +00:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2017-10-13 16:50:36 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|