Sha256: 00fb32a764f087664986e2939fbe7ea6fa7bdce731c84dc846e1dacef29413b6

Contents?: true

Size: 999 Bytes

Versions: 10

Compression:

Stored size: 999 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 => error
        log.error = formatted_exception(error)
        log.status = :error
        log.save!
        raise error
      end

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

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
renalware-core-2.0.44 app/models/renalware/ukrdc/transmission_log.rb
renalware-core-2.0.43 app/models/renalware/ukrdc/transmission_log.rb
renalware-core-2.0.42 app/models/renalware/ukrdc/transmission_log.rb
renalware-core-2.0.41 app/models/renalware/ukrdc/transmission_log.rb
renalware-core-2.0.40 app/models/renalware/ukrdc/transmission_log.rb
renalware-core-2.0.39 app/models/renalware/ukrdc/transmission_log.rb
renalware-core-2.0.38 app/models/renalware/ukrdc/transmission_log.rb
renalware-core-2.0.37 app/models/renalware/ukrdc/transmission_log.rb
renalware-core-2.0.36 app/models/renalware/ukrdc/transmission_log.rb
renalware-core-2.0.35 app/models/renalware/ukrdc/transmission_log.rb