Sha256: 52f2dede49c0dc98161ff1312ae9bbdfcff8c25671df512a34093357b0a25469

Contents?: true

Size: 1.61 KB

Versions: 56

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

56 entries across 56 versions & 1 rubygems

Version Path
hephaestus-0.8.16.1 app/jobs/hephaestus/update_yetto_job.rb
hephaestus-0.8.16 app/jobs/hephaestus/update_yetto_job.rb
hephaestus-0.8.15.5 app/jobs/hephaestus/update_yetto_job.rb
hephaestus-0.8.15.4 app/jobs/hephaestus/update_yetto_job.rb
hephaestus-0.8.15.3 app/jobs/hephaestus/update_yetto_job.rb
hephaestus-0.8.15.2 app/jobs/hephaestus/update_yetto_job.rb
hephaestus-0.8.15.1 app/jobs/hephaestus/update_yetto_job.rb
hephaestus-0.8.15 app/jobs/hephaestus/update_yetto_job.rb
hephaestus-0.8.14 app/jobs/hephaestus/update_yetto_job.rb
hephaestus-0.8.13 app/jobs/hephaestus/update_yetto_job.rb
hephaestus-0.8.12.2 app/jobs/hephaestus/update_yetto_job.rb
hephaestus-0.8.12.1 app/jobs/hephaestus/update_yetto_job.rb
hephaestus-0.8.12 app/jobs/hephaestus/update_yetto_job.rb
hephaestus-0.8.11 app/jobs/hephaestus/update_yetto_job.rb
hephaestus-0.8.10 app/jobs/hephaestus/update_yetto_job.rb
hephaestus-0.8.9.2 app/jobs/hephaestus/update_yetto_job.rb
hephaestus-0.8.9.1 app/jobs/hephaestus/update_yetto_job.rb
hephaestus-0.8.9 app/jobs/hephaestus/update_yetto_job.rb
hephaestus-0.8.8 app/jobs/hephaestus/update_yetto_job.rb
hephaestus-0.8.7.5 app/jobs/hephaestus/update_yetto_job.rb