28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/event_source/get.rb', line 28
def call(stream_name=nil, position: nil)
position ||= 0
logger.trace(tag: :control) { "Getting (Position: #{position}, Batch Size: #{batch_size}, Stream Name: #{stream_name.inspect})" }
logger.debug(tags: [:control, :data]) { "Items: \n#{items.pretty_inspect}" }
logger.debug(tag: :control) { "Position: #{position.inspect}" }
logger.debug(tag: :control) { "Batch Size: #{batch_size.inspect}" }
unless EventSource::StreamName.category?(stream_name)
index = (items.index { |i| i.position >= position })
else
index = (items.index { |i| i.global_position >= position })
end
logger.debug(tag: :control) { "Index: #{index.inspect}" }
if index.nil?
items = []
else
range = index..(index + batch_size - 1)
logger.debug(tag: :control) { "Range: #{range.pretty_inspect}" }
items = self.items[range]
end
logger.info(tags: [:control, :data]) { "Got: \n#{items.pretty_inspect}" }
logger.info(tag: :control) { "Finished getting (Position: #{position}, Stream Name: #{stream_name.inspect})" }
items
end
|