Sha256: a739db3d4d20c3f5a40d85d0d0dfa2711a2f84b6d80d6bdc197a9b443791e7d8

Contents?: true

Size: 1.21 KB

Versions: 6

Compression:

Stored size: 1.21 KB

Contents

module PhobosDBCheckpoint
  class Failure < ActiveRecord::Base
    include PhobosDBCheckpoint::EventHelper

    def self.record(event:, event_metadata:, exception: nil)
      return if exists?(event_metadata[:checksum])

      create do |record|
        record.topic           = event_metadata[:topic]
        record.group_id        = event_metadata[:group_id]
        record.entity_id       = event.fetch_entity_id
        record.event_time      = event.fetch_event_time
        record.event_type      = event.fetch_event_type
        record.event_version   = event.fetch_event_version
        record.checksum        = event_metadata[:checksum]
        record.payload         = event.payload
        record.metadata        = event_metadata
        record.error_class     = exception&.class&.name
        record.error_message   = exception&.message
        record.error_backtrace = exception&.backtrace
      end
    end

    def self.exists?(checksum)
      where(checksum: checksum).exists?
    end

    def payload
      attributes['payload'].deep_symbolize_keys
    end

    def metadata
      attributes['metadata'].deep_symbolize_keys
    end

    def group_id
      attributes['group_id'] || metadata[:group_id]
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
phobos_db_checkpoint-2.2.0 lib/phobos_db_checkpoint/failure.rb
phobos_db_checkpoint-2.1.0 lib/phobos_db_checkpoint/failure.rb
phobos_db_checkpoint-2.0.0 lib/phobos_db_checkpoint/failure.rb
phobos_db_checkpoint-2.0.0.rc1 lib/phobos_db_checkpoint/failure.rb
phobos_db_checkpoint-1.1.0 lib/phobos_db_checkpoint/failure.rb
phobos_db_checkpoint-1.0.0 lib/phobos_db_checkpoint/failure.rb