Class: SQS::Job::Handler
- Inherits:
-
Object
- Object
- SQS::Job::Handler
- Defined in:
- lib/sqs/job/handler.rb
Overview
One Handler instance is created per SQS message received, and is responsible for processing it by instantiating a Message::Base subclass and calling its #invoke! method. The “main” method is #run!.
Messages have the following structure: ‘create’, params: { … } Where params is optional (for example, keepalive messages might not have params).
The message class is loaded by requiring ‘vm2/message/#type’ constantizing it in the normal way, and passing the params hash to #new.
Instance Method Summary collapse
-
#initialize(sqs_message) ⇒ Handler
constructor
A new instance of Handler.
-
#run! ⇒ Object
Run this handler.
Constructor Details
#initialize(sqs_message) ⇒ Handler
Returns a new instance of Handler.
17 18 19 |
# File 'lib/sqs/job/handler.rb', line 17 def initialize @sqs_message = end |
Instance Method Details
#run! ⇒ Object
Run this handler
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/sqs/job/handler.rb', line 22 def run! require 'base64' fingerprint = @sqs_message.['key_fingerprint'][:string_value] signature = Base64.strict_decode64(@sqs_message.['signature'][:string_value]) raise SignatureInvalidException unless SQS::Job.signature_valid? @sqs_message.body, fingerprint, signature msg = JSON.parse(@sqs_message.body) raise MissingTypeException unless (type = msg['type']) klass = type SQS::Job.logger.info "Received message #{klass}" = klass.new(msg['params'] || {}) raise InvalidMessageException, unless .valid? .invoke! end |