Class: Karafka::Web::Management::Actions::CreateInitialStates

Inherits:
Base
  • Object
show all
Defined in:
lib/karafka/web/management/actions/create_initial_states.rb

Overview

Creates the records needed for the Web-UI to operate. It creates “almost” empty states because the rest is handled via migrations

Constant Summary collapse

DEFAULT_STATE =

Whole default empty state This will be further migrated by the migrator

{
  schema_version: '0.0.0'
}.freeze
DEFAULT_METRICS =

Default metrics state

{
  schema_version: '0.0.0'
}.freeze

Instance Method Summary collapse

Instance Method Details

#callObject

Creates the initial states for the Web-UI if needed (if they don’t exist)



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
# File 'lib/karafka/web/management/actions/create_initial_states.rb', line 22

def call
  if exists?(Karafka::Web.config.topics.consumers.states)
    exists('consumers state')
  else
    creating('consumers state')
    ::Karafka::Web.producer.produce_sync(
      topic: Karafka::Web.config.topics.consumers.states,
      key: Karafka::Web.config.topics.consumers.states,
      payload: DEFAULT_STATE.to_json
    )
    created('consumers state')
  end

  if exists?(Karafka::Web.config.topics.consumers.metrics)
    exists('consumers metrics')
  else
    creating('consumers metrics')
    ::Karafka::Web.producer.produce_sync(
      topic: Karafka::Web.config.topics.consumers.metrics,
      key: Karafka::Web.config.topics.consumers.metrics,
      payload: DEFAULT_METRICS.to_json
    )
    created('consumers metrics')
  end
end