debian-mirror-gitlab/app/models/concerns/import_state/sidekiq_job_tracker.rb

27 lines
804 B
Ruby
Raw Normal View History

2020-04-22 19:07:51 +05:30
# frozen_string_literal: true
module ImportState
module SidekiqJobTracker
extend ActiveSupport::Concern
included do
2020-06-23 00:09:42 +05:30
scope :with_jid, -> { where.not(jid: nil) }
scope :without_jid, -> { where(jid: nil) }
2020-04-22 19:07:51 +05:30
# Refreshes the expiration time of the associated import job ID.
#
# This method can be used by asynchronous importers to refresh the status,
2020-06-23 00:09:42 +05:30
# preventing the Gitlab::Import::StuckProjectImportJobsWorker from marking the import as failed.
2020-04-22 19:07:51 +05:30
def refresh_jid_expiration
return unless jid
2020-06-23 00:09:42 +05:30
Gitlab::SidekiqStatus.set(jid, Gitlab::Import::StuckImportJob::IMPORT_JOBS_EXPIRATION)
2020-04-22 19:07:51 +05:30
end
def self.jid_by(project_id:, status:)
select(:jid).where(status: status).find_by(project_id: project_id)
end
end
end
end