Class: EventSource::EventStore::HTTP::Get
- Inherits:
-
Object
- Object
- EventSource::EventStore::HTTP::Get
- Includes:
- Log::Dependency
- Defined in:
- lib/event_source/event_store/http/get.rb,
lib/event_source/event_store/http/get/last.rb,
lib/event_source/event_store/http/get/result.rb,
lib/event_source/event_store/http/get/assertions.rb
Defined Under Namespace
Modules: Assertions, Defaults, Result Classes: Last
Class Method Summary collapse
- .build(batch_size: nil, precedence: nil, long_poll_duration: nil, session: nil) ⇒ Object
- .call(stream_name, position: nil, **build_arguments) ⇒ Object
Instance Method Summary collapse
- #call(stream_name, position: nil) ⇒ Object
- #configure ⇒ Object
- #desc_position(stream_name, position) ⇒ Object
- #direction ⇒ Object
- #precedence ⇒ Object
Class Method Details
.build(batch_size: nil, precedence: nil, long_poll_duration: nil, session: nil) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/event_source/event_store/http/get.rb', line 18 def self.build(batch_size: nil, precedence: nil, long_poll_duration: nil, session: nil) instance = new batch_size, precedence, long_poll_duration session = Session.configure instance, session: session ::EventStore::HTTP::ReadStream.configure instance, session: session instance.configure instance end |
.call(stream_name, position: nil, **build_arguments) ⇒ Object
28 29 30 31 |
# File 'lib/event_source/event_store/http/get.rb', line 28 def self.call(stream_name, position: nil, **build_arguments) instance = build **build_arguments instance.(stream_name, position: position) end |
Instance Method Details
#call(stream_name, position: nil) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/event_source/event_store/http/get.rb', line 42 def call(stream_name, position: nil) stream_name = StreamName.canonize stream_name logger.trace { "Reading stream (StreamName: #{stream_name}, Position: #{position || '(start)'}, Direction: #{direction}, BatchSize: #{batch_size})" } if precedence == :desc position = desc_position stream_name, position if position < 0 logger.debug { "Reading backward across start of stream (StreamName: #{stream_name}, Position: #{position || '(start)'}, Direction: #{direction}, BatchSize: #{batch_size}, Events: 0)" } return [] end end begin events = read_stream.( stream_name, position: position, direction: direction, batch_size: batch_size ) rescue ::EventStore::HTTP::ReadStream::StreamNotFoundError events = [] end events.reverse! if precedence == :desc logger.debug { "Done reading stream (StreamName: #{stream_name}, Position: #{position || '(start)'}, Direction: #{direction}, BatchSize: #{batch_size}, Events: #{events.count})" } events end |
#configure ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/event_source/event_store/http/get.rb', line 33 def configure read_stream. read_stream.output_schema = Result unless long_poll_duration.nil? read_stream.enable_long_poll long_poll_duration end end |
#desc_position(stream_name, position) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/event_source/event_store/http/get.rb', line 74 def desc_position(stream_name, position) begin head_event, * = read_stream.( stream_name, position: :head, direction: :backward, batch_size: 1 ) rescue ::EventStore::HTTP::ReadStream::StreamNotFoundError return -1 end if position.nil? head_event.position else head_event.position - position end end |
#direction ⇒ Object
93 94 95 96 97 98 99 |
# File 'lib/event_source/event_store/http/get.rb', line 93 def direction if precedence == :asc :forward else :backward end end |
#precedence ⇒ Object
11 12 13 |
# File 'lib/event_source/event_store/http/get.rb', line 11 def precedence @precedence ||= Defaults.precedence end |