debian-mirror-gitlab/app/models/bulk_import.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

72 lines
1.8 KiB
Ruby
Raw Normal View History

2021-01-03 14:25:43 +05:30
# frozen_string_literal: true
2021-01-29 00:20:46 +05:30
# The BulkImport model links all models required for a bulk import of groups and
# projects to a GitLab instance. It associates the import with the responsible
# user.
2021-01-03 14:25:43 +05:30
class BulkImport < ApplicationRecord
2021-11-18 22:05:49 +05:30
MIN_MAJOR_VERSION = 14
MIN_MINOR_VERSION_FOR_PROJECT = 4
2021-09-30 23:02:18 +05:30
2021-01-03 14:25:43 +05:30
belongs_to :user, optional: false
has_one :configuration, class_name: 'BulkImports::Configuration'
has_many :entities, class_name: 'BulkImports::Entity'
validates :source_type, :status, presence: true
enum source_type: { gitlab: 0 }
2022-06-21 17:19:12 +05:30
scope :stale, -> { where('created_at < ?', 8.hours.ago).where(status: [0, 1]) }
2023-03-04 22:38:38 +05:30
scope :order_by_created_at, ->(direction) { order(created_at: direction) }
2022-06-21 17:19:12 +05:30
2021-01-03 14:25:43 +05:30
state_machine :status, initial: :created do
state :created, value: 0
2021-01-29 00:20:46 +05:30
state :started, value: 1
state :finished, value: 2
2022-06-21 17:19:12 +05:30
state :timeout, value: 3
2021-01-29 00:20:46 +05:30
state :failed, value: -1
event :start do
transition created: :started
end
event :finish do
transition started: :finished
end
2022-06-21 17:19:12 +05:30
event :cleanup_stale do
transition created: :timeout
transition started: :timeout
end
2021-01-29 00:20:46 +05:30
event :fail_op do
transition any => :failed
end
2023-05-27 22:25:52 +05:30
# rubocop:disable Style/SymbolProc
after_transition any => [:finished, :failed, :timeout] do |bulk_import|
bulk_import.update_has_failures
end
# rubocop:enable Style/SymbolProc
2021-01-03 14:25:43 +05:30
end
2021-09-30 23:02:18 +05:30
2021-11-18 22:05:49 +05:30
def source_version_info
Gitlab::VersionInfo.parse(source_version)
end
def self.min_gl_version_for_project_migration
Gitlab::VersionInfo.new(MIN_MAJOR_VERSION, MIN_MINOR_VERSION_FOR_PROJECT)
end
2021-09-30 23:02:18 +05:30
def self.all_human_statuses
state_machine.states.map(&:human_name)
end
2023-05-27 22:25:52 +05:30
def update_has_failures
return if has_failures
return unless entities.any?(&:has_failures)
update!(has_failures: true)
end
2021-01-03 14:25:43 +05:30
end