Sha256: 1b325e62fc9ee33b3c75159cb967a5341dd350a0d2babd6751f7f75dbbd05b30
Contents?: true
Size: 1006 Bytes
Versions: 11
Compression:
Stored size: 1006 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{ |line| "\t#{line}" } ].join("\n") end end end end
Version data entries
11 entries across 11 versions & 1 rubygems