mongoriver 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
@@ -8,6 +8,9 @@ module Mongoriver
|
|
8
8
|
class AbstractPersistentTailer < Tailer
|
9
9
|
attr_reader :last_saved, :last_read
|
10
10
|
|
11
|
+
# How often to save position to database
|
12
|
+
DEFAULT_SAVE_FREQUENCY = 60.0
|
13
|
+
|
11
14
|
def initialize(upstream, type, opts={})
|
12
15
|
raise "You can't instantiate an AbstractPersistentTailer -- did you want PersistentTailer? " if self.class == AbstractPersistentTailer
|
13
16
|
super(upstream, type)
|
@@ -15,6 +18,7 @@ module Mongoriver
|
|
15
18
|
@last_saved = {}
|
16
19
|
@batch = opts[:batch]
|
17
20
|
@last_read = {}
|
21
|
+
@save_frequency = opts[:save_frequency] || DEFAULT_SAVE_FREQUENCY
|
18
22
|
end
|
19
23
|
|
20
24
|
def tail(opts={})
|
@@ -24,7 +28,7 @@ module Mongoriver
|
|
24
28
|
end
|
25
29
|
|
26
30
|
def stream(limit=nil)
|
27
|
-
start_time =
|
31
|
+
start_time = connection_config['localTime']
|
28
32
|
found_entry = false
|
29
33
|
|
30
34
|
# Sketchy logic - yield results from Tailer.stream
|
@@ -39,6 +43,10 @@ module Mongoriver
|
|
39
43
|
|
40
44
|
if !found_entry && !entries_left
|
41
45
|
@last_read['time'] = start_time
|
46
|
+
if @last_read['position'].nil?
|
47
|
+
@last_read['position'] ||= read_position
|
48
|
+
@last_read['position'] ||= most_recent_position(start_time)
|
49
|
+
end
|
42
50
|
maybe_save_state unless @batch
|
43
51
|
end
|
44
52
|
|
@@ -92,16 +100,15 @@ module Mongoriver
|
|
92
100
|
if state.nil?
|
93
101
|
state = last_read
|
94
102
|
end
|
103
|
+
return unless state['position']
|
95
104
|
write_state(state)
|
96
105
|
@last_saved = state
|
97
106
|
log.info("Saved state: #{last_saved}")
|
98
107
|
end
|
99
108
|
|
100
109
|
def maybe_save_state
|
101
|
-
# Write position once a minute
|
102
|
-
|
103
110
|
return unless last_read['time']
|
104
|
-
if last_saved['time'].nil? || last_read['time'] - last_saved['time'] >
|
111
|
+
if last_saved['time'].nil? || last_read['time'] - last_saved['time'] > @save_frequency
|
105
112
|
save_state
|
106
113
|
end
|
107
114
|
end
|
data/lib/mongoriver/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoriver
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-09-
|
12
|
+
date: 2014-09-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: mongo
|