Module: Ocpp::Rails::StateChangeHookManager

Defined in:
app/services/ocpp/rails/state_change_hook_manager.rb

Class Method Summary collapse

Class Method Details

.execute_hooks(state_change) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/services/ocpp/rails/state_change_hook_manager.rb', line 4

def self.execute_hooks(state_change)
  hooks = Ocpp::Rails.configuration.state_change_hooks

  hooks.each do |hook|
    begin
      if hook.respond_to?(:async?) && hook.async?
        # Enqueue async hook job
        Ocpp::Rails::AsyncHookJob.perform_later(state_change.id, hook.class.name)
      else
        # Execute synchronously
        hook.call(state_change)
      end
    rescue => error
      ::Rails.logger.error("StateChangeHook #{hook.class.name} failed: #{error.message}")
      ::Rails.logger.error(error.backtrace.join("\n"))
    end
  end

  true
end