Sha256: 6b2a02e01465b9ae623200a455803f299b8e3706e47d97b04df7cfbadac7b515
Contents?: true
Size: 1.31 KB
Versions: 2
Compression:
Stored size: 1.31 KB
Contents
#!/usr/bin/env ruby require 'rubygems' require 'simperium' require 'uri' require 'mongo' require 'optparse' MONGOHQ_URL = ENV['MONGOHQ_URL'] uri = URI.parse(MONGOHQ_URL) conn = Mongo::Connection.from_uri(MONGOHQ_URL) $db = conn.db(uri.path.gsub(/^\//, '')) def main(appname, admin_key, bucket) _bucket = Bucket.new(appname, admin_key, bucket) begin cv = $db['__meta__'].find_one cv = cv['cv'] rescue StandardError => e cv = nil end begin while true do changes = _bucket.all(:cv => cv, :data=>true) for change in changes data = change['d'] # update mongo with the latest version of the data if data data['_id'] = change['id'] # puts data $db[bucket].save(data) else $db[bucket].remove({'_id' => change['id']}) end # persist the cv to mongo, so changes don't need to be # re-processed after restart $db['__meta__'].save({'_id' => 'cv', 'cv' => change['cv']}) cv = change['cv'] end end rescue StandardError => e raise StandardError.new('Mirroring failed') end end main(ARGV[0], ARGV[1], ARGV[2])
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
simperium-0.0.2.3 | lib/simperium/listener-export-mongohq |
simperium-0.0.2.2 | lib/simperium/listener-export-mongohq |