Sha256: 52f2dede49c0dc98161ff1312ae9bbdfcff8c25671df512a34093357b0a25469

Contents?: true

Size: 1.61 KB

Versions: 57

Compression:

Stored size: 1.61 KB

Contents

# typed: false
# frozen_string_literal: true

# Send updated data to Yetto to store in the database
# This can be used to update installation data or message data
module Hephaestus
  class UpdateYettoJob < ApplicationJob
    queue_as :high_priority_update_yetto

    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
  end
end

Version data entries

57 entries across 57 versions & 1 rubygems

Version Path
hephaestus-0.8.7.5 app/jobs/hephaestus/update_yetto_job.rb
hephaestus-0.8.7.4 app/jobs/hephaestus/update_yetto_job.rb
hephaestus-0.8.7.3 app/jobs/hephaestus/update_yetto_job.rb
hephaestus-0.8.7.2 app/jobs/hephaestus/update_yetto_job.rb
hephaestus-0.8.7.1 app/jobs/hephaestus/update_yetto_job.rb
hephaestus-0.8.7 app/jobs/hephaestus/update_yetto_job.rb
hephaestus-0.8.6 app/jobs/hephaestus/update_yetto_job.rb
hephaestus-0.8.5 app/jobs/hephaestus/update_yetto_job.rb
hephaestus-0.8.4.1 app/jobs/hephaestus/update_yetto_job.rb
hephaestus-0.8.4 app/jobs/hephaestus/update_yetto_job.rb
hephaestus-0.8.3.4 app/jobs/hephaestus/update_yetto_job.rb
hephaestus-0.8.3.3 app/jobs/hephaestus/update_yetto_job.rb
hephaestus-0.8.3.2 app/jobs/hephaestus/update_yetto_job.rb
hephaestus-0.8.3.1 app/jobs/hephaestus/update_yetto_job.rb
hephaestus-0.8.3 app/jobs/hephaestus/update_yetto_job.rb
hephaestus-0.8.2 app/jobs/hephaestus/update_yetto_job.rb
hephaestus-0.8.1 app/jobs/hephaestus/update_yetto_job.rb
hephaestus-0.8.0 app/jobs/hephaestus/update_yetto_job.rb
hephaestus-0.7.7.2 app/jobs/hephaestus/update_yetto_job.rb
hephaestus-0.7.7 app/jobs/hephaestus/update_yetto_job.rb