Class: Consumer::Postgres::PositionStore

Inherits:
Object
  • Object
show all
Includes:
Consumer::PositionStore, Initializer
Defined in:
lib/consumer/postgres/position_store.rb,
lib/consumer/postgres/position_store/recorded.rb,
lib/consumer/postgres/position_store/stream_name.rb

Defined Under Namespace

Modules: StreamName Classes: Recorded

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.build(stream_name, session: nil, consumer_identifier: nil) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/consumer/postgres/position_store.rb', line 13

def self.build(stream_name, session: nil, consumer_identifier: nil)
  position_stream_name = StreamName.position_stream_name(stream_name, consumer_identifier: consumer_identifier)

  instance = new(position_stream_name)
  MessageStore::Postgres::Session.configure(instance, session: session)
  instance.configure
  instance
end

Instance Method Details

#configureObject



22
23
24
25
26
27
28
29
30
# File 'lib/consumer/postgres/position_store.rb', line 22

def configure
  MessageStore::Postgres::Get::Last.configure(
    self,
    session: session,
    attr_name: :read
  )

  Messaging::Postgres::Write.configure(self, session: session)
end

#getObject



32
33
34
35
36
37
38
39
40
# File 'lib/consumer/postgres/position_store.rb', line 32

def get
  message_data = read.(stream_name)

  return nil if message_data.nil?

  message = Messaging::Message::Import.(message_data, Recorded)

  message.position
end

#put(position) ⇒ Object



42
43
44
45
46
47
# File 'lib/consumer/postgres/position_store.rb', line 42

def put(position)
  message = Recorded.new
  message.position = position

  write.(message, stream_name)
end