Class: Hephaestus::UpdateYettoJob

Inherits:
ApplicationJob show all
Defined in:
app/jobs/hephaestus/update_yetto_job.rb

Instance Method Summary collapse

Instance Method Details

#perform(params) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/jobs/hephaestus/update_yetto_job.rb', line 10

def perform(params)
  type = params.delete(:type)
  params.deep_symbolize_keys!

  inbox_id = params.fetch(:inbox, {}).fetch(:id, nil)
  plug_installation_id = params.fetch(:plug_installation, {}).fetch(:id, nil)
  conversation_id = params.fetch(:conversation, {}).fetch(:id, nil)
  message_id = params.fetch(:message, {}).fetch(:id, nil)

  response = case type
  when "update_plug_installation"
    YettoService.update_plug_installation(plug_installation_id, params[:payload])
  when "create_conversation"
    YettoService.create_conversation(plug_installation_id, inbox_id, params[:payload])
  when "add_message_to_conversation"
    YettoService.add_message_to_conversation(plug_installation_id, conversation_id, params[:payload])
  when "create_message_reply"
    YettoService.create_message_reply(plug_installation_id, message_id, params[:payload])
  when "update_message"
    YettoService.update_message(plug_installation_id, message_id, params[:payload])
  end

  response, type = Rails.configuration.enhance_update_yetto_job.call(params, type, response) if Rails.configuration.respond_to?(:enhance_update_yetto_job)

  if response.present? && response.unavailable?
    logger.error("Could not #{type} for #{plug_installation_id}: #{response.parsed_json_body}")
  end
end