Class: Alephant::Publisher::Queue::RevalidateProcessor

Inherits:
Processor
  • Object
show all
Includes:
Logger
Defined in:
lib/alephant/publisher/queue/revalidate_processor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = nil, url_generator, http_response_processor) ⇒ RevalidateProcessor

Returns a new instance of RevalidateProcessor.



17
18
19
20
21
# File 'lib/alephant/publisher/queue/revalidate_processor.rb', line 17

def initialize(opts = nil, url_generator, http_response_processor)
  @opts                    = opts
  @url_generator           = url_generator
  @http_response_processor = http_response_processor
end

Instance Attribute Details

#http_response_processorObject (readonly)

Returns the value of attribute http_response_processor.



15
16
17
# File 'lib/alephant/publisher/queue/revalidate_processor.rb', line 15

def http_response_processor
  @http_response_processor
end

#optsObject (readonly)

Returns the value of attribute opts.



15
16
17
# File 'lib/alephant/publisher/queue/revalidate_processor.rb', line 15

def opts
  @opts
end

#url_generatorObject (readonly)

Returns the value of attribute url_generator.



15
16
17
# File 'lib/alephant/publisher/queue/revalidate_processor.rb', line 15

def url_generator
  @url_generator
end

Instance Method Details

#consume(message) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/alephant/publisher/queue/revalidate_processor.rb', line 23

def consume(message)
  return if message.nil?

  msg_body = message_content(message)

  http_response = {
    renderer_id:   msg_body.fetch(:id),
    http_options:  msg_body,
    http_response: get(message),
    ttl:           http_response_processor.ttl(msg_body)
  }

  http_message = build_http_message(message, ::JSON.generate(http_response))

  write(http_message)

  message.delete
  logger.info(event: 'SQSMessageDeleted', message_content: message_content(message), method: "#{self.class}#consume")

  cache.delete(inflight_message_key(message))
  logger.info(event: 'InFlightMessageDeleted', key: inflight_message_key(message), method: "#{self.class}#consume")
end