Class: Storage::Algolia::Actions::Get

Inherits:
Base show all
Defined in:
lib/storage/algolia/actions/get.rb

Constant Summary collapse

MAX_RETRIES =
3

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationService

process

Constructor Details

#initialize(model_name:, id:) ⇒ Get

Returns a new instance of Get.



13
14
15
16
17
# File 'lib/storage/algolia/actions/get.rb', line 13

def initialize(model_name:, id:)
  @model_name = model_name
  @id = id
  @retries = 0
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



11
12
13
# File 'lib/storage/algolia/actions/get.rb', line 11

def id
  @id
end

#model_nameObject (readonly)

Returns the value of attribute model_name.



11
12
13
# File 'lib/storage/algolia/actions/get.rb', line 11

def model_name
  @model_name
end

#retriesObject (readonly)

Returns the value of attribute retries.



11
12
13
# File 'lib/storage/algolia/actions/get.rb', line 11

def retries
  @retries
end

Instance Method Details

#processObject



19
20
21
22
23
24
25
26
27
# File 'lib/storage/algolia/actions/get.rb', line 19

def process
  @retries += 1
  normalize index.get_object(id).deep_transform_keys(&:to_sym)
rescue => e
  pp "Retrying (#{@retries}/#{MAX_RETRIES})..."
  sleep 2
  retry if @retries <= MAX_RETRIES
  raise Exception
end