Class: Karafka::Web::Pro::Ui::Controllers::ScheduledMessages::SchedulesController

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

Overview

Controller to display list of schedules (groups) and details about each

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

Displays list of groups



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/karafka/web/pro/ui/controllers/scheduled_messages/schedules_controller.rb', line 41

def index
  topics = Models::Topic.all

  # Names of scheduled messages topics defined in the routing
  # They may not exist (yet) so we filter them based on the existing topics in the
  # cluster
  candidates = Karafka::App
    .routes
    .map { |route| route.topics.to_a }
    .flatten
    .select(&:scheduled_messages?)
    .reject { |topic| topic.name.end_with?(states_postfix) }
    .map(&:name)
    .sort

  @topics = topics.select { |topic| candidates.include?(topic.topic_name) }

  render
end

#show(schedule_name) ⇒ Object

Displays all partitions statistics (if any) with number of messages to dispatch

Parameters:

  • schedule_name (String)

    name of the schedules messages topic



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/karafka/web/pro/ui/controllers/scheduled_messages/schedules_controller.rb', line 63

def show(schedule_name)
  @schedule_name = schedule_name
  @stats_topic_name = "#{schedule_name}#{states_postfix}"
  @stats_info = Karafka::Admin.topic_info(@stats_topic_name)

  @states = {}
  @stats_info[:partition_count].times { |i| @states[i] = false }

  Karafka::Pro::Iterator.new({ @stats_topic_name => -1 }).each do |message|
    @states[message.partition] = message.payload
  end

  # Sort by partition id
  @states = @states.sort_by { |key, _| key.to_s }.to_h
  # Sort daily from closest date
  @states.each_value do |details|
    # Skip false predefined values from sorting
    next unless details

    details[:daily] = details[:daily].sort_by { |key, _| key.to_s }.to_h
  end

  render
end