Class: Ocpp::Rails::AsyncHookJob

Inherits:
ApplicationJob show all
Defined in:
app/jobs/ocpp/rails/async_hook_job.rb

Instance Method Summary collapse

Instance Method Details

#perform(state_change_id, hook_class_name) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/jobs/ocpp/rails/async_hook_job.rb', line 8

def perform(state_change_id, hook_class_name)
  state_change = Ocpp::Rails::StateChange.find_by(id: state_change_id)

  unless state_change
    ::Rails.logger.warn("StateChange #{state_change_id} not found, may have been cleaned up")
    return
  end

  hook_class = hook_class_name.constantize
  hook = hook_class.new
  hook.call(state_change)
rescue => error
  ::Rails.logger.error("AsyncHook #{hook_class_name} failed for StateChange #{state_change_id}: #{error.message}")
  raise
end