Class: CircuitSwitch::DueDateNotifier

Inherits:
ActiveJob::Base
  • Object
show all
Defined in:
lib/circuit_switch/workers/due_date_notifier.rb

Instance Method Summary collapse

Instance Method Details

#performObject

Raises:



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/circuit_switch/workers/due_date_notifier.rb', line 7

def perform
  raise CircuitSwitchError.new('Set config.due_date_notifier.') unless config.due_date_notifier

  circuit_switches = CircuitSwitch.where('due_date <= ?', Date.today).order(id: :asc)
  if circuit_switches.present?
    message = "Due date has come! Let's consider about removing switches and cleaning up code! :)\n" +
      circuit_switches.map { |switch|  "id: #{switch.id}, key: '#{switch.key}', caller: '#{switch.caller}', created_at: #{switch.created_at}" }.join("\n")
    config.due_date_notifier.call(message)
  else
    switches_count = CircuitSwitch.all.size
    message = switches_count.zero? ? 'There is no switch!' : "#{switches_count} switches are waiting for their due_date."
    config.due_date_notifier.call(message)
  end
end