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

Inherits:
BaseController show all
Defined in:
lib/karafka/web/pro/ui/controllers/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 Method Summary collapse

Methods inherited from Ui::Controllers::BaseController

#initialize

Constructor Details

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

Instance Method Details

#indexObject

Lists commands from the consumers commands topic



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/karafka/web/pro/ui/controllers/commands_controller.rb', line 22

def index
  @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



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

def recent
  # 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



46
47
48
49
50
51
52
53
54
55
# File 'lib/karafka/web/pro/ui/controllers/commands_controller.rb', line 46

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

  render
end