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

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

Overview

Provides management of schedules related messages

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

#cancel(topic_id, partition_id, message_offset) ⇒ Object

Generates a cancel request for a given schedule message

Parameters:

  • topic_id (String)
  • partition_id (Integer)
  • message_offset (Integer)


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/karafka/web/pro/ui/controllers/scheduled_messages/messages_controller.rb', line 26

def cancel(topic_id, partition_id, message_offset)
  # Fetches the message we want to cancel to get its key
  scheduled_message = Karafka::Admin.read_topic(
    topic_id,
    partition_id,
    1,
    message_offset
  ).first

  cancel_message = ::Karafka::Pro::ScheduledMessages.cancel(
    key: scheduled_message.key,
    envelope: {
      topic: topic_id,
      partition: partition_id
    }
  )

  Karafka::Web.producer.produce_sync(cancel_message)

  redirect(
    :back,
    success: <<~MESSAGE
      A scheduled message with offset #{message_offset}
      from #{topic_id} partition #{partition_id}
      had a cancel request message successfully created.
    MESSAGE
  )
end