summaryrefslogtreecommitdiff
path: root/app/models/clusters/concerns/application_status.rb
blob: 7bb68d75224ef7f196d3ebdd69ebfc9393c97e55 (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
module Clusters
  module Concerns
    module ApplicationStatus
      extend ActiveSupport::Concern

      included do
        state_machine :status, initial: :installable do
          state :errored, value: -1
          state :installable, value: 0
          state :scheduled, value: 1
          state :installing, value: 2
          state :installed, value: 3

          event :make_installing do
            transition any - [:installing] => :installing
          end

          event :make_installed do
            transition any - [:installed] => :installed
          end

          event :make_errored do
            transition any - [:errored] => :errored
          end

          event :make_scheduled do
            transition any - [:scheduled] => :scheduled
          end

          before_transition any => [:scheduled] do |app_status, _|
            app_status.status_reason = nil
          end

          before_transition any => [:errored] do |app_status, transition|
            status_reason = transition.args.first
            app_status.status_reason = status_reason if status_reason
          end
        end
      end
    end
  end
end