Sha256: c8080473458a9bda09a9fb3cb7fde051151ad2839e6d7b2045e55b1ba58afda0

Contents?: true

Size: 952 Bytes

Versions: 6

Compression:

Stored size: 952 Bytes

Contents

# frozen_string_literal: true

module Karafka
  # App status monitor
  class Status
    # Available states and their transitions.
    STATES = {
      initializing: :initialize!,
      initialized: :initialized!,
      running: :run!,
      quieting: :quiet!,
      stopping: :stop!,
      stopped: :stopped!
    }.freeze

    private_constant :STATES

    # By default we are in the initializing state
    def initialize
      initialize!
    end

    STATES.each do |state, transition|
      define_method :"#{state}?" do
        @status == state
      end

      define_method transition do
        # Do nothing if the state change would change nothing (same state)
        return if @status == state

        @status = state

        # Skip on creation (initializing)
        # We skip as during this state we do not have yet a monitor
        return if initializing?

        Karafka.monitor.instrument("app.#{state}")
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
karafka-2.0.23 lib/karafka/status.rb
karafka-2.0.22 lib/karafka/status.rb
karafka-2.0.21 lib/karafka/status.rb
karafka-2.0.20 lib/karafka/status.rb
karafka-2.0.19 lib/karafka/status.rb
karafka-2.0.18 lib/karafka/status.rb