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

batch_tracker.rb « bulk_imports « models « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2e79d41d46ec2f3c1394926f42b7fcce9a6c28af (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
# frozen_string_literal: true

module BulkImports
  class BatchTracker < ApplicationRecord
    self.table_name = 'bulk_import_batch_trackers'

    belongs_to :tracker, class_name: 'BulkImports::Tracker'

    validates :batch_number, presence: true, uniqueness: { scope: :tracker_id }

    state_machine :status, initial: :created do
      state :created, value: 0
      state :started, value: 1
      state :finished, value: 2
      state :timeout, value: 3
      state :failed, value: -1
      state :skipped, value: -2

      event :start do
        transition created: :started
      end

      event :retry do
        transition started: :created
      end

      event :finish do
        transition any => :finished
      end

      event :skip do
        transition any => :skipped
      end

      event :fail_op do
        transition any => :failed
      end

      event :cleanup_stale do
        transition [:created, :started] => :timeout
      end
    end
  end
end