Class: Karafka::Web::Pro::Ui::Controllers::Consumers::CommandsController

Inherits:
BaseController show all
Defined in:
lib/karafka/web/pro/ui/controllers/consumers/commands_controller.rb

Overview

Controller for viewing details of dispatched commands and their results

Constant Summary

Constants inherited from Ui::Controllers::BaseController

Ui::Controllers::BaseController::Models

Instance Attribute Summary

Attributes inherited from Ui::Controllers::BaseController

#params, #session

Instance Method Summary collapse

Methods inherited from Ui::Controllers::BaseController

#cache, #initialize

Methods included from Ui::Controllers::Requests::Hookable

included, #run_after_hooks, #run_before_hooks

Constructor Details

This class inherits a constructor from Karafka::Web::Ui::Controllers::BaseController

Instance Method Details

#indexObject

Lists commands from the consumers commands topic



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/karafka/web/pro/ui/controllers/consumers/commands_controller.rb', line 15

def index
  features.commanding!

  @schema_version = Commanding::Dispatcher::SCHEMA_VERSION
  @watermark_offsets = Models::WatermarkOffsets.find(commands_topic, 0)

  previous_offset, @command_messages, next_offset = current_partition_data

  # If message is an array, it means it's a compacted dummy offset representation
  mapped_messages = @command_messages.map do |message|
    message.is_a?(Array) ? message.last : message.offset
  end

  paginate(
    previous_offset,
    @params.current_offset,
    next_offset,
    mapped_messages
  )

  render
end

#recentObject

Displays the most recent available command message details



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/karafka/web/pro/ui/controllers/consumers/commands_controller.rb', line 55

def recent
  features.commanding!

  # We read 25 just in case there would be a lot of transactional noise
  messages = ::Karafka::Admin.read_topic(commands_topic, 0, 25)

  # We find the most recent (last since they are shipped in reverse order)
  recent = messages.reverse.find { |message| !message.is_a?(Array) }

  return show(recent.offset) if recent

  # If nothing found, lets redirect user back to the commands list
  redirect(
    'commands',
    warning: 'No recent commands available'
  )
end

#show(offset) ⇒ Object

Shows details about given command / result

Parameters:

  • offset (Integer)

    offset of the command message we’re interested in



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/karafka/web/pro/ui/controllers/consumers/commands_controller.rb', line 41

def show(offset)
  features.commanding!

  @schema_version = Commanding::Dispatcher::SCHEMA_VERSION
  @command_message = Models::Message.find(
    commands_topic,
    0,
    offset
  )

  render
end