Commit 488afee0 authored by Alexandru Croitor's avatar Alexandru Croitor

Extract sidekiq job tracking to a separate concer

Reuse sidekiq job tracking as a concern on import state models
parent c35f6d5e
# frozen_string_literal: true
module ImportState
module SidekiqJobTracker
extend ActiveSupport::Concern
included do
# Refreshes the expiration time of the associated import job ID.
#
# This method can be used by asynchronous importers to refresh the status,
# preventing the StuckImportJobsWorker from marking the import as failed.
def refresh_jid_expiration
return unless jid
Gitlab::SidekiqStatus.set(jid, StuckImportJobsWorker::IMPORT_JOBS_EXPIRATION)
end
def self.jid_by(project_id:, status:)
select(:jid).with_status(status).find_by(project_id: project_id)
end
end
end
end
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
class JiraImportState < ApplicationRecord class JiraImportState < ApplicationRecord
include AfterCommitQueue include AfterCommitQueue
include ImportState::SidekiqJobTracker
self.table_name = 'jira_imports' self.table_name = 'jira_imports'
...@@ -66,14 +67,4 @@ class JiraImportState < ApplicationRecord ...@@ -66,14 +67,4 @@ class JiraImportState < ApplicationRecord
def in_progress? def in_progress?
scheduled? || started? scheduled? || started?
end end
def refresh_jid_expiration
return unless jid
Gitlab::SidekiqStatus.set(jid, StuckImportJobsWorker::IMPORT_JOBS_EXPIRATION)
end
def self.jid_by(project_id:, status:)
select(:jid).with_status(status).find_by(project_id: project_id)
end
end end
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
class ProjectImportState < ApplicationRecord class ProjectImportState < ApplicationRecord
include AfterCommitQueue include AfterCommitQueue
include ImportState::SidekiqJobTracker
self.table_name = "project_mirror_data" self.table_name = "project_mirror_data"
...@@ -88,20 +89,6 @@ class ProjectImportState < ApplicationRecord ...@@ -88,20 +89,6 @@ class ProjectImportState < ApplicationRecord
# import? does SQL work so only run it if it looks like there's an import running # import? does SQL work so only run it if it looks like there's an import running
status == 'started' && project.import? status == 'started' && project.import?
end end
# Refreshes the expiration time of the associated import job ID.
#
# This method can be used by asynchronous importers to refresh the status,
# preventing the StuckImportJobsWorker from marking the import as failed.
def refresh_jid_expiration
return unless jid
Gitlab::SidekiqStatus.set(jid, StuckImportJobsWorker::IMPORT_JOBS_EXPIRATION)
end
def self.jid_by(project_id:, status:)
select(:jid).with_status(status).find_by(project_id: project_id)
end
end end
ProjectImportState.prepend_if_ee('EE::ProjectImportState') ProjectImportState.prepend_if_ee('EE::ProjectImportState')
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