Class: Karafka::Web::Ui::Models::RecurringTasks::Schedule

Inherits:
Lib::HashProxy
  • Object
show all
Defined in:
lib/karafka/web/ui/models/recurring_tasks/schedule.rb

Overview

Karafka schedule representation

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Lib::HashProxy

#initialize, #method_missing, #respond_to_missing?, #to_h

Constructor Details

This class inherits a constructor from Karafka::Web::Ui::Lib::HashProxy

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Karafka::Web::Ui::Lib::HashProxy

Class Method Details

.currentSchedule, false

Returns current schedule or false if it was not possible to get it because requested topic/partition does not exist or nothing was present.

Returns:

  • (Schedule, false)

    current schedule or false if it was not possible to get it because requested topic/partition does not exist or nothing was present



23
24
25
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
54
55
56
# File 'lib/karafka/web/ui/models/recurring_tasks/schedule.rb', line 23

def current
  messages = Karafka::Admin.read_topic(
    config.topics.schedules,
    0,
    # We work here with the assumption that users won't click so fast to load
    # more than 20 commands prior to a state flush. If that happens, this will
    # return false. This is a known and expected limitation.
    20
  )

  # Out of those messages we pick the most recent persisted schedule
  candidate = messages
              .reverse
              .find { |message| message.key == 'state:schedule' }

  # If there is a schedule message we use its data to build schedule, if not false
  return false unless candidate

  # If the deserializer is not our dedicated recurring tasks deserializer, it means
  # that routing for recurring tasks was not loaded, so recurring tasks are not
  # active
  #
  # User might have used recurring tasks previously and disabled them, but still may
  # navigate to them and then we should not show anything because without the
  # correct deserializer it will crash anyhow
  return false unless candidate..deserializers.payload == config.deserializer

  new(candidate.payload)
rescue Rdkafka::RdkafkaError => e
  # If any of "topic missing" is raised, we return false but other errors we re-raise
  raise(e) unless EXPECTED_RDKAFKA_ERRORS.any? { |code| e.code == code }

  false
end

Instance Method Details

#tasksArray<Task>

Returns tasks of the current schedule.

Returns:

  • (Array<Task>)

    tasks of the current schedule



67
68
69
# File 'lib/karafka/web/ui/models/recurring_tasks/schedule.rb', line 67

def tasks
  @tasks ||= super.values.map { |task_hash| Task.new(task_hash) }
end