Module: RocketJob::Subscriber

Extended by:
ActiveSupport::Concern
Included in:
RocketJob::Subscribers::Logger, RocketJob::Subscribers::SecretConfig, RocketJob::Subscribers::Server, RocketJob::Subscribers::Worker
Defined in:
lib/rocket_job/subscriber.rb

Overview

Mix-in to publish and subscribe to events.

Example: def MySubscriber

include RocketJob::Subscriber

def hello
  logger.info "Hello Action Received"
end

def show(message:)
  logger.info "Received: #{message}"
end

# If `message` is not supplied it defaults to "Hello World"
def show_default(message: "Hello World")
  logger.info "Received: #{message}"
end

end

MySubscriber.subscribe

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.test_mode!Object

Test Mode Bypasses publishing the event and calls the subscribers directly



30
31
32
# File 'lib/rocket_job/subscriber.rb', line 30

def self.test_mode!
  @test_mode = true
end

.test_mode?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/rocket_job/subscriber.rb', line 34

def self.test_mode?
  @test_mode
end

Instance Method Details

#process_action(action, parameters) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/rocket_job/subscriber.rb', line 63

def process_action(action, parameters)
  unless public_methods.include?(action)
    logger.warn("Ignoring unknown action: #{action}")
    return
  end

  args = method(action).arity.zero? || parameters.nil? ? nil : parameters.symbolize_keys
  args ? public_send(action, **args) : public_send(action)
rescue ArgumentError => e
  logger.error("##{action}: Invalid Arguments. Resuming..", e)
rescue StandardError => e
  logger.error("##{action}: Exception caught. Resuming..", e)
end

#process_event(name, action, parameters) ⇒ Object

Raises:

  • (NotImplementedError)


77
78
79
# File 'lib/rocket_job/subscriber.rb', line 77

def process_event(name, action, parameters)
  raise(NotImplementedError)
end