Welcome to mirror list, hosted at ThFree Co, Russian Federation.

project_repository_storage_move.rb « models « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e88cc5cfca628f6549a4437a6d3455d506c743c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# frozen_string_literal: true

# ProjectRepositoryStorageMove are details of repository storage moves for a
# project. For example, moving a project to another gitaly node to help
# balance storage capacity.
class ProjectRepositoryStorageMove < ApplicationRecord
  include AfterCommitQueue

  belongs_to :project, inverse_of: :repository_storage_moves

  validates :project, presence: true
  validates :state, presence: true
  validates :source_storage_name,
    on: :create,
    presence: true,
    inclusion: { in: ->(_) { Gitlab.config.repositories.storages.keys } }
  validates :destination_storage_name,
    on: :create,
    presence: true,
    inclusion: { in: ->(_) { Gitlab.config.repositories.storages.keys } }

  state_machine initial: :initial do
    event :schedule do
      transition initial: :scheduled
    end

    event :start do
      transition scheduled: :started
    end

    event :finish do
      transition started: :finished
    end

    event :do_fail do
      transition [:initial, :scheduled, :started] => :failed
    end

    after_transition initial: :scheduled do |storage_move, _|
      storage_move.run_after_commit do
        ProjectUpdateRepositoryStorageWorker.perform_async(
          storage_move.project_id,
          storage_move.destination_storage_name,
          storage_move.id
        )
      end
    end

    state :initial, value: 1
    state :scheduled, value: 2
    state :started, value: 3
    state :finished, value: 4
    state :failed, value: 5
  end

  scope :order_created_at_desc, -> { order(created_at: :desc) }
  scope :with_projects, -> { includes(project: :route) }
end