Sha256: 088dd6b2dd74d3d3acf8d665a46cc72ee2dac8c0741c59cbc06c4315acec3779

Contents?: true

Size: 707 Bytes

Versions: 3

Compression:

Stored size: 707 Bytes

Contents

module PhobosDBCheckpoint
  class Event < ActiveRecord::Base
    after_initialize :assign_checksum

    def exists?
      Event.where(topic: topic, group_id: group_id, checksum: checksum).exists?
    end

    def acknowledge!(ack)
      self.entity_id = ack.entity_id
      self.event_time = ack.event_time
      self.event_type = ack.event_type
      self.event_version = ack.event_version
      save!
    end

    def configured_handler
      Phobos
        .config
        .listeners
        .find { |listener| listener.group_id == self.group_id }
        &.handler
    end

    private

    def assign_checksum
      self.checksum ||= Digest::MD5.hexdigest(payload.to_json) if payload
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
phobos_db_checkpoint-0.5.0 lib/phobos_db_checkpoint/event.rb
phobos_db_checkpoint-0.4.0 lib/phobos_db_checkpoint/event.rb
phobos_db_checkpoint-0.3.0 lib/phobos_db_checkpoint/event.rb