Sha256: 020e35924942f40be8e4fbdfcca3e527fe69d031542fbe88939e4a5cb2551014

Contents?: true

Size: 996 Bytes

Versions: 18

Compression:

Stored size: 996 Bytes

Contents

# frozen_string_literal: true

require_dependency "renalware/ukrdc"

module Renalware
  module UKRDC
    class TransmissionLog < ApplicationRecord
      validates :sent_at, presence: true
      validates :status, presence: true
      belongs_to :patient, class_name: "Renalware::Patient"
      enum status: [:undefined, :error, :unsent_no_change_since_last_send, :sent]
      scope :ordered, -> { order(sent_at: :asc) }

      def self.with_logging(patient, request_uuid)
        log = new(patient: patient, sent_at: Time.zone.now, request_uuid: request_uuid)
        yield log if block_given?
        log.save!
      rescue StandardError => e
        log.error << formatted_exception(e)
        log.status = :error
        log.save!
        raise e
      end

      def self.formatted_exception(error)
        [
          "#{error.backtrace.first}: #{error.message} (#{error.class})",
          error.backtrace.drop(1).map { |line| "\t#{line}" }
        ].join("\n")
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
renalware-core-2.0.101 app/models/renalware/ukrdc/transmission_log.rb
renalware-core-2.0.100 app/models/renalware/ukrdc/transmission_log.rb
renalware-core-2.0.99 app/models/renalware/ukrdc/transmission_log.rb
renalware-core-2.0.98 app/models/renalware/ukrdc/transmission_log.rb
renalware-core-2.0.97 app/models/renalware/ukrdc/transmission_log.rb
renalware-core-2.0.96 app/models/renalware/ukrdc/transmission_log.rb
renalware-core-2.0.95 app/models/renalware/ukrdc/transmission_log.rb
renalware-core-2.0.94 app/models/renalware/ukrdc/transmission_log.rb
renalware-core-2.0.93 app/models/renalware/ukrdc/transmission_log.rb
renalware-core-2.0.92 app/models/renalware/ukrdc/transmission_log.rb
renalware-core-2.0.91 app/models/renalware/ukrdc/transmission_log.rb
renalware-core-2.0.90 app/models/renalware/ukrdc/transmission_log.rb
renalware-core-2.0.89 app/models/renalware/ukrdc/transmission_log.rb
renalware-core-2.0.88 app/models/renalware/ukrdc/transmission_log.rb
renalware-core-2.0.87 app/models/renalware/ukrdc/transmission_log.rb
renalware-core-2.0.86 app/models/renalware/ukrdc/transmission_log.rb
renalware-core-2.0.85 app/models/renalware/ukrdc/transmission_log.rb
renalware-core-2.0.84 app/models/renalware/ukrdc/transmission_log.rb