Class: Neuromancer::Indexer::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/neuromancer/indexer/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sqs = nil) ⇒ Client

Returns a new instance of Client.



8
9
10
11
# File 'lib/neuromancer/indexer/client.rb', line 8

def initialize(sqs = nil)
  @config = Neuromancer::Indexer.config
  @sqs = sqs
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



6
7
8
# File 'lib/neuromancer/indexer/client.rb', line 6

def config
  @config
end

Instance Method Details

#delete(id:, type:) ⇒ Object



20
21
22
23
24
25
# File 'lib/neuromancer/indexer/client.rb', line 20

def delete(id:, type:)
  document = Document.new(id: id, type: type, attributes: {})
  document.validate!

  enqueue(action: 'delete', document: document)
end

#enqueue(action:, document:) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/neuromancer/indexer/client.rb', line 27

def enqueue(action:, document:)
  message = {
    action: action,
    document: document
  }

  sqs.send_message(
    queue_url: config.sqs_url,
    message_body: message.to_json,
    delay_seconds: 1
  )
end

#index(id:, type:, attributes:) ⇒ Object



13
14
15
16
17
18
# File 'lib/neuromancer/indexer/client.rb', line 13

def index(id:, type:, attributes:)
  document = Document.new(id: id, type: type, attributes: attributes)
  document.validate!

  enqueue(action: 'index', document: document)
end