mongo_delta 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -40,7 +40,8 @@ targets:
40
40
  archive: mongodb://mongoarch:27017
41
41
 
42
42
  outlets:
43
- - outlet: Replicator
43
+ event_archiver:
44
+ outlet: Replicator
44
45
  target: archive
45
46
  db: db_name
46
47
  collection: events
@@ -81,17 +82,19 @@ Example:
81
82
  $ mongo mongo_delta
82
83
  rs0:PRIMARY> db.config.save({
83
84
  ... _id: 'mongo_delta',
84
- ... outlets: [{
85
- ... outlet: 'Replicator',
86
- ... target: 'live',
87
- ... db: 'sourcedb',
88
- ... collection: 'events',
89
- ... target_db: 'archive'
90
- ... }],
85
+ ... outlets: {
86
+ ... event_archiver: {
87
+ ... outlet: 'Replicator',
88
+ ... target: 'live',
89
+ ... db: 'sourcedb',
90
+ ... collection: 'events',
91
+ ... target_db: 'archive'
92
+ ... }
93
+ ... },
91
94
  ... targets: {live: 'mongodb://localhost:27017'}
92
95
  ... })
93
96
  $ mongo_delta --source mongodb://localhost:27017
94
- 2013-06-10 21:24:29 - INFO: Registering Replicator outlet for cartman.events
97
+ 2013-06-10 21:24:29 - INFO: Registering event_archiver Replicator outlet for cartman.events
95
98
  2013-06-10 21:24:29 - INFO: Starting stream
96
99
  ```
97
100
 
@@ -4,7 +4,8 @@ targets:
4
4
  archive: mongodb://localhost:27017
5
5
 
6
6
  outlets:
7
- - outlet: Replicator
7
+ event_archiver:
8
+ outlet: Replicator
8
9
  target: archive
9
10
  db: dbname
10
11
  collection: events
@@ -5,23 +5,34 @@ module MongoDelta
5
5
 
6
6
  attr_reader :outlets
7
7
 
8
- def initialize
9
- @outlets = []
8
+ def initialize(options={})
9
+ @outlets = {}
10
+ @options = options
10
11
  end
11
12
 
12
- %w(insert remove update).each do |method|
13
+ %w(insert remove update create_index drop_index create_collection drop_collection rename_collection).each do |method|
13
14
 
14
15
  define_method(method) do |db, collection, *args|
15
16
  logger.debug "#{method} for #{db}.#{collection}: #{args.map(&:inspect).join(' ')}"
16
17
 
17
- outlets.each do |outlet|
18
- if outlet.handles?(db, collection, method)
19
- outlet.send(method, *args)
18
+ outlets.each do |key, outlet|
19
+ begin
20
+ if outlet.handles?(db, collection, method)
21
+ outlet.send(method, *args)
22
+ end
23
+ rescue
24
+ logger.error "#{key} outlet could not transfer document: #{$!.message}"
25
+ logger.error "=> #{db}.#{collection} #{args.map(&:inspect).join(' ')}"
26
+ raise unless ignore_errors?
20
27
  end
21
28
  end
22
29
  end
23
30
 
24
31
  end
25
32
 
33
+ def ignore_errors?
34
+ @options[:ignore_errors]
35
+ end
36
+
26
37
  end
27
38
  end
@@ -8,7 +8,7 @@ module MongoDelta
8
8
 
9
9
  include MongoDelta::Logging
10
10
 
11
- attr_accessor :config_path, :source_uri, :optime, :db, :service
11
+ attr_accessor :config_path, :source_uri, :optime, :db, :service, :ignore_errors
12
12
 
13
13
  def start
14
14
  parse_options
@@ -22,6 +22,7 @@ module MongoDelta
22
22
  end
23
23
  config.db = db
24
24
  config.service = service
25
+ config.ignore_errors = ignore_errors
25
26
 
26
27
  stream = Stream.new(config)
27
28
  stream.run(optime)
@@ -51,6 +52,11 @@ module MongoDelta
51
52
  exit(1)
52
53
  end
53
54
 
55
+ opts.on('--version', 'Display version and exit') do
56
+ puts MongoDelta::VERSION
57
+ exit(1)
58
+ end
59
+
54
60
  opts.on('-c FILE', '--config', 'Configuration file') do |path|
55
61
  self.config_path = path
56
62
  end
@@ -70,6 +76,10 @@ module MongoDelta
70
76
  opts.on('-o OPTIME', '--optime', 'Starting optime') do |optime|
71
77
  self.optime = Integer(optime)
72
78
  end
79
+
80
+ opts.on('--ignore-errors', 'Ignore transfer errors') do
81
+ self.ignore_errors = true
82
+ end
73
83
  end
74
84
  optparse.parse!
75
85
  end
@@ -56,10 +56,10 @@ module MongoDelta
56
56
  def validate!
57
57
  raise Error, "Missing source" unless source
58
58
  raise Error, "Missing outlets" unless outlets and not outlets.empty?
59
- outlets.each do |outlet|
60
- key = outlet['target']
61
- target = (targets || {})[key]
62
- raise Error, "Missing target '#{key}'" unless target
59
+ outlets.each do |key, outlet|
60
+ target_key = outlet['target']
61
+ target = (targets || {})[target_key]
62
+ raise Error, "Missing target '#{target_key}'" unless target
63
63
  end
64
64
  end
65
65
 
@@ -77,5 +77,12 @@ module MongoDelta
77
77
  @options['service'] = service
78
78
  end
79
79
 
80
+ def ignore_errors
81
+ !!@options['ignore_errors']
82
+ end
83
+ def ignore_errors=(bool)
84
+ @options['ignore_errors'] = bool
85
+ end
86
+
80
87
  end
81
88
  end
@@ -11,7 +11,7 @@ module MongoDelta
11
11
  def initialize(config)
12
12
  @config = config
13
13
  @tailer = Mongoriver::PersistentTailer.new([@config.source], :existing, @config.service, :db => @config.db)
14
- @agent = MongoDelta::Agent.new
14
+ @agent = MongoDelta::Agent.new(:ignore_errors => config.ignore_errors)
15
15
  @stream = Mongoriver::Stream.new(@tailer, @agent)
16
16
  setup_outlets
17
17
  end
@@ -25,10 +25,10 @@ module MongoDelta
25
25
  private
26
26
 
27
27
  def setup_outlets
28
- @config.outlets.each do |options|
28
+ @config.outlets.each do |key, options|
29
29
  outlet = MongoDelta::Outlet.from_options(@config, options)
30
- logger.info "Registering #{options['outlet']} outlet for #{outlet.ns}"
31
- @agent.outlets << outlet
30
+ logger.info "Registering #{key} #{options['outlet']} outlet for #{outlet.ns}"
31
+ @agent.outlets[key] = outlet
32
32
  end
33
33
  end
34
34
 
@@ -1,3 +1,3 @@
1
1
  module MongoDelta
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -2,14 +2,14 @@
2
2
  name: mongo_delta
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.0
5
+ version: 0.2.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Laszlo Bacsi
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-10 00:00:00.000000000 Z
12
+ date: 2013-06-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  prerelease: false
@@ -97,7 +97,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
97
97
  - !ruby/object:Gem::Version
98
98
  segments:
99
99
  - 0
100
- hash: -1239396457491943967
100
+ hash: -3914604556798742908
101
101
  version: '0'
102
102
  none: false
103
103
  required_rubygems_version: !ruby/object:Gem::Requirement
@@ -106,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
106
  - !ruby/object:Gem::Version
107
107
  segments:
108
108
  - 0
109
- hash: -1239396457491943967
109
+ hash: -3914604556798742908
110
110
  version: '0'
111
111
  none: false
112
112
  requirements: []