mongoriver 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -25,7 +25,7 @@ module Mongoriver
25
25
  end
26
26
 
27
27
  def main
28
- options = {:host => nil, :port => nil, :type => :direct, :optime => 0, :pause => true, :verbose => 0}
28
+ options = {:host => nil, :port => nil, :type => :direct, :optime => nil, :pause => true, :verbose => 0}
29
29
  optparse = OptionParser.new do |opts|
30
30
  opts.banner = "Usage: #{$0} [options]"
31
31
 
@@ -77,7 +77,7 @@ def main
77
77
  end
78
78
  end
79
79
 
80
- stream.run_forever
80
+ stream.run_forever(options[:optime])
81
81
  return 0
82
82
  end
83
83
 
@@ -15,11 +15,9 @@ module Mongoriver
15
15
  @last_read = nil
16
16
  end
17
17
 
18
- def tail_from(ts, opts={})
19
- if ts.nil?
20
- ts = read_timestamp
21
- end
22
- super(ts, opts)
18
+ def tail(opts={})
19
+ opts[:from] ||= read_timestamp
20
+ super(opts)
23
21
  end
24
22
 
25
23
  def stream(limit=nil)
@@ -23,9 +23,9 @@ module Mongoriver
23
23
 
24
24
  def run_forever(starting_timestamp=nil)
25
25
  if starting_timestamp
26
- @tailer.tail_from(optime_from_ts(starting_timestamp))
26
+ @tailer.tail(:from => optime_from_ts(starting_timestamp))
27
27
  else
28
- @tailer.tail_from
28
+ @tailer.tail
29
29
  end
30
30
 
31
31
  until @stop
@@ -166,4 +166,4 @@ module Mongoriver
166
166
  trigger(:create_collection, db_name, collection_name, options)
167
167
  end
168
168
  end
169
- end
169
+ end
@@ -67,23 +67,31 @@ module Mongoriver
67
67
  @upstream_conn.db('local').collection(oplog)
68
68
  end
69
69
 
70
- def tail_from(ts, opts = {})
70
+ def tail(opts = {})
71
71
  raise "Already tailing the oplog!" if @cursor
72
72
 
73
- # Maybe if ts is old enough, just start from the beginning?
74
- query = (opts[:filter] || {}).merge({ 'ts' => { '$gte' => ts } })
73
+ query = opts[:filter] || {}
74
+ if ts = opts[:from]
75
+ # Maybe if ts is old enough, just start from the beginning?
76
+ query['ts'] = { '$gte' => ts }
77
+ end
75
78
 
76
79
  oplog_collection.find(query, :timeout => false) do |oplog|
77
80
  oplog.add_option(Mongo::Constants::OP_QUERY_TAILABLE)
78
- oplog.add_option(Mongo::Constants::OP_QUERY_OPLOG_REPLAY)
79
-
81
+ oplog.add_option(Mongo::Constants::OP_QUERY_OPLOG_REPLAY) if query['ts']
80
82
  oplog.add_option(Mongo::Constants::OP_QUERY_AWAIT_DATA) unless opts[:dont_wait]
81
83
 
82
- log.info("Starting oplog stream from #{ts}")
84
+ log.info("Starting oplog stream from #{ts || 'start'}")
83
85
  @cursor = oplog
84
86
  end
85
87
  end
86
88
 
89
+ # Deprecated: use #tail(:from => ts, ...) instead
90
+ def tail_from(ts, opts={})
91
+ opts.merge(:from => ts)
92
+ tail(opts)
93
+ end
94
+
87
95
  def stream(limit=nil)
88
96
  count = 0
89
97
  while !@stop && @cursor.has_next?
@@ -1,3 +1,3 @@
1
1
  module Mongoriver
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
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.2.0
4
+ version: 0.3.0
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: 2013-05-07 00:00:00.000000000 Z
12
+ date: 2013-06-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mongo