Sha256: 853326367be8cfd2657ce8863c244841727274f68a5d6f00b436f84bc2598e44

Contents?: true

Size: 740 Bytes

Versions: 9

Compression:

Stored size: 740 Bytes

Contents

# frozen_string_literal: true

require_dependency "renalware/system"

module Renalware
  module System
    class APILog < ApplicationRecord
      validates :identifier, presence: true
      validates :status, presence: true
      STATUS_WORKING = "working"
      STATUS_DONE = "done"
      STATUS_ERROR = "error"

      def self.with_log(identifier, **args)
        log = create!(identifier: identifier, status: STATUS_WORKING, **args)
        yield(log) if block_given?
        log.update!(status: STATUS_DONE)
        log

      rescue StandardError => e
        log.update(
          status: STATUS_ERROR,
          error: "#{$ERROR_INFO}\nBacktrace:\n\t#{e.backtrace.join("\n\t")}"
        )
        raise e
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
renalware-core-2.0.87 app/models/renalware/system/api_log.rb
renalware-core-2.0.86 app/models/renalware/system/api_log.rb
renalware-core-2.0.85 app/models/renalware/system/api_log.rb
renalware-core-2.0.84 app/models/renalware/system/api_log.rb
renalware-core-2.0.83 app/models/renalware/system/api_log.rb
renalware-core-2.0.82 app/models/renalware/system/api_log.rb
renalware-core-2.0.81 app/models/renalware/system/api_log.rb
renalware-core-2.0.80 app/models/renalware/system/api_log.rb
renalware-core-2.0.79 app/models/renalware/system/api_log.rb