Sha256: 54332c5c45fbd1834efc715b9c6f823a45fa3397b04dd09939f85bc36ffd7111

Contents?: true

Size: 927 Bytes

Versions: 4

Compression:

Stored size: 927 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!,
      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

4 entries across 4 versions & 1 rubygems

Version Path
karafka-2.0.17 lib/karafka/status.rb
karafka-2.0.16 lib/karafka/status.rb
karafka-2.0.15 lib/karafka/status.rb
karafka-2.0.14 lib/karafka/status.rb