Class: SolidQueue::Dispatcher::RecurringSchedule

Inherits:
Object
  • Object
show all
Includes:
AppExecutor
Defined in:
lib/solid_queue/dispatcher/recurring_schedule.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from AppExecutor

#handle_thread_error, #wrap_in_app_executor

Constructor Details

#initialize(tasks) ⇒ RecurringSchedule

Returns a new instance of RecurringSchedule.



9
10
11
12
# File 'lib/solid_queue/dispatcher/recurring_schedule.rb', line 9

def initialize(tasks)
  @configured_tasks = Array(tasks).map { |task| Dispatcher::RecurringTask.wrap(task) }
  @scheduled_tasks = Concurrent::Hash.new
end

Instance Attribute Details

#configured_tasksObject (readonly)

Returns the value of attribute configured_tasks.



7
8
9
# File 'lib/solid_queue/dispatcher/recurring_schedule.rb', line 7

def configured_tasks
  @configured_tasks
end

#scheduled_tasksObject (readonly)

Returns the value of attribute scheduled_tasks.



7
8
9
# File 'lib/solid_queue/dispatcher/recurring_schedule.rb', line 7

def scheduled_tasks
  @scheduled_tasks
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/solid_queue/dispatcher/recurring_schedule.rb', line 14

def empty?
  configured_tasks.empty?
end

#inspectObject



37
38
39
# File 'lib/solid_queue/dispatcher/recurring_schedule.rb', line 37

def inspect
  configured_tasks.map(&:to_s).join(" | ")
end

#load_task(task) ⇒ Object



24
25
26
# File 'lib/solid_queue/dispatcher/recurring_schedule.rb', line 24

def load_task(task)
  scheduled_tasks[task.key] = schedule(task)
end

#load_tasksObject



18
19
20
21
22
# File 'lib/solid_queue/dispatcher/recurring_schedule.rb', line 18

def load_tasks
  configured_tasks.each do |task|
    load_task(task)
  end
end

#tasksObject



33
34
35
# File 'lib/solid_queue/dispatcher/recurring_schedule.rb', line 33

def tasks
  configured_tasks.each_with_object({}) { |task, hsh| hsh[task.key] = task.to_h }
end

#unload_tasksObject



28
29
30
31
# File 'lib/solid_queue/dispatcher/recurring_schedule.rb', line 28

def unload_tasks
  scheduled_tasks.values.each(&:cancel)
  scheduled_tasks.clear
end