Method: Karafka::Pro::RecurringTasks::Serializer#schedule

Defined in:
lib/karafka/pro/recurring_tasks/serializer.rb

#schedule(schedule) ⇒ String

Serializes and compresses the schedule with all its tasks and their execution state

Parameters:

Returns:

  • (String)

    serialized and compressed current schedule data with its tasks and their current state.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/karafka/pro/recurring_tasks/serializer.rb', line 18

def schedule(schedule)
  tasks = {}

  schedule.each do |task|
    tasks[task.id] = {
      id: task.id,
      cron: task.cron.original,
      previous_time: task.previous_time.to_i,
      next_time: task.next_time.to_i,
      enabled: task.enabled?
    }
  end

  data = {
    schema_version: SCHEMA_VERSION,
    schedule_version: schedule.version,
    dispatched_at: Time.now.to_f,
    type: 'schedule',
    tasks: tasks
  }

  compress(
    serialize(data)
  )
end