Sha256: 7eb4d88aa0be7a60aca6b2d486798c921915bf2c6e073f7a2b822d0fb7a5ff88

Contents?: true

Size: 979 Bytes

Versions: 23

Compression:

Stored size: 979 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!
      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

23 entries across 23 versions & 1 rubygems

Version Path
renalware-core-2.0.34 app/models/renalware/ukrdc/transmission_log.rb
renalware-core-2.0.33 app/models/renalware/ukrdc/transmission_log.rb
renalware-core-2.0.32 app/models/renalware/ukrdc/transmission_log.rb
renalware-core-2.0.31 app/models/renalware/ukrdc/transmission_log.rb
renalware-core-2.0.30 app/models/renalware/ukrdc/transmission_log.rb
renalware-core-2.0.28 app/models/renalware/ukrdc/transmission_log.rb
renalware-core-2.0.27 app/models/renalware/ukrdc/transmission_log.rb
renalware-core-2.0.26 app/models/renalware/ukrdc/transmission_log.rb
renalware-core-2.0.25 app/models/renalware/ukrdc/transmission_log.rb
renalware-core-2.0.24 app/models/renalware/ukrdc/transmission_log.rb
renalware-core-2.0.23 app/models/renalware/ukrdc/transmission_log.rb
renalware-core-2.0.22 app/models/renalware/ukrdc/transmission_log.rb
renalware-core-2.0.21 app/models/renalware/ukrdc/transmission_log.rb
renalware-core-2.0.20 app/models/renalware/ukrdc/transmission_log.rb
renalware-core-2.0.18 app/models/renalware/ukrdc/transmission_log.rb
renalware-core-2.0.17 app/models/renalware/ukrdc/transmission_log.rb
renalware-core-2.0.16 app/models/renalware/ukrdc/transmission_log.rb
renalware-core-2.0.15 app/models/renalware/ukrdc/transmission_log.rb
renalware-core-2.0.14 app/models/renalware/ukrdc/transmission_log.rb
renalware-core-2.0.13 app/models/renalware/ukrdc/transmission_log.rb