barnyard_harvester 0.0.3 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/barnyard_harvester.gemspec +2 -1
- data/lib/barnyard_harvester.rb +6 -1
- data/lib/barnyard_harvester/mongodb.rb +141 -0
- data/lib/barnyard_harvester/mongodb_helper.rb +72 -0
- data/lib/barnyard_harvester/mongodb_queue.rb +84 -0
- data/lib/barnyard_harvester/version.rb +1 -1
- data/spec/mongo_helper_spec.rb +61 -0
- data/spec/mongo_spec.rb +180 -0
- metadata +42 -13
data/barnyard_harvester.gemspec
CHANGED
data/lib/barnyard_harvester.rb
CHANGED
@@ -14,7 +14,7 @@ module BarnyardHarvester
|
|
14
14
|
|
15
15
|
attr_reader :my_barn, :my_add_queue, :my_change_queue, :my_delete_queue
|
16
16
|
attr_reader :add_count, :change_count, :delete_count, :source_count, :cache_count
|
17
|
-
attr_reader :
|
17
|
+
attr_reader :redis_settings
|
18
18
|
attr_reader :harvester_uuid, :backend, :crop_number
|
19
19
|
|
20
20
|
def initialize(args)
|
@@ -27,6 +27,11 @@ module BarnyardHarvester
|
|
27
27
|
|
28
28
|
@backend = args.fetch(:backend) { :redis }
|
29
29
|
|
30
|
+
if @backend == :mongodb
|
31
|
+
@mongodb_settings = args.fetch(:mongodb_settings) { raise "You must provide :mongodb_settings" }
|
32
|
+
end
|
33
|
+
|
34
|
+
require "barnyard_harvester/#{@backend.to_s}_helper" if File.exist? "barnyard_harvester/#{@backend.to_s}_helper"
|
30
35
|
require "barnyard_harvester/#{@backend.to_s}_queue"
|
31
36
|
require "barnyard_harvester/#{@backend.to_s}"
|
32
37
|
|
@@ -0,0 +1,141 @@
|
|
1
|
+
require "mongo"
|
2
|
+
require "crack"
|
3
|
+
require "json"
|
4
|
+
require "resque"
|
5
|
+
require "barnyard_harvester/mongodb_helper"
|
6
|
+
|
7
|
+
#
|
8
|
+
#require "lib/barnyard_harvester/mongodb_helper"
|
9
|
+
|
10
|
+
module BarnyardHarvester
|
11
|
+
|
12
|
+
class HarvesterLogs
|
13
|
+
@queue = :logs_harvester
|
14
|
+
end
|
15
|
+
|
16
|
+
DEFAULT_MONGO_SETTINGS = {
|
17
|
+
:host_list => "localhost:27017",
|
18
|
+
:collection => "test_collection",
|
19
|
+
:db => "test_db"
|
20
|
+
}
|
21
|
+
|
22
|
+
class Barn
|
23
|
+
|
24
|
+
def initialize(args)
|
25
|
+
|
26
|
+
@crop_number = args.fetch(:crop_number) { raise "You must provide :crop_number" }
|
27
|
+
@redis_settings = args.fetch(:redis_settings) { DEFAULT_REDIS_SETTINGS }
|
28
|
+
@mongodb_settings = args.fetch(:mongodb_settings) { MongoSettings }
|
29
|
+
@debug = args.fetch(:debug) { false }
|
30
|
+
@log = args.fetch(:logger) { Logger.new(STDOUT) }
|
31
|
+
|
32
|
+
@mongodb_settings.fetch(:db) { raise "You must provide :db" }
|
33
|
+
@mongodb_settings.fetch(:collection) { raise "You must provide :collection" }
|
34
|
+
|
35
|
+
@redis_settings.delete(:db)
|
36
|
+
Resque.redis = Redis.new(@redis_settings)
|
37
|
+
|
38
|
+
@mongodb_settings[:debug] = @debug
|
39
|
+
@mongodb_settings[:logger] = @log
|
40
|
+
|
41
|
+
@mongo = BarnyardHarvester::MongoDbHelper.connect @mongodb_settings
|
42
|
+
|
43
|
+
@collection_name = @mongodb_settings[:collection]
|
44
|
+
@collection = @mongo.collection(@mongodb_settings[:collection])
|
45
|
+
|
46
|
+
@collection
|
47
|
+
end
|
48
|
+
|
49
|
+
def log_run(harvester_uuid, crop_number, began_at, ended_at, source_count, change_count, add_count, delete_count)
|
50
|
+
|
51
|
+
begin
|
52
|
+
Resque.enqueue(HarvesterLogs, Time.now, harvester_uuid, crop_number, began_at, ended_at, source_count, change_count, add_count, delete_count)
|
53
|
+
rescue Exception => e
|
54
|
+
logger.fatal "#{self.class} Fail in Resque.enqueue of HarvesterLogs. #{e.backtrace}"
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
def delete(primary_key)
|
60
|
+
check_key primary_key
|
61
|
+
|
62
|
+
value = @collection.find "_id" => primary_key # Save the value
|
63
|
+
|
64
|
+
@collection.remove("_id" => primary_key)
|
65
|
+
|
66
|
+
value.to_json # Return the object
|
67
|
+
end
|
68
|
+
|
69
|
+
def []= primary_key, object
|
70
|
+
check_key primary_key
|
71
|
+
check_object object
|
72
|
+
|
73
|
+
obj = Crack::JSON.parse object.to_json
|
74
|
+
|
75
|
+
# We artificially add the _id value to the object as this is the primary key
|
76
|
+
# This is stored in the Mongo database, but removed upon a fetch.
|
77
|
+
|
78
|
+
if obj.is_a?(Hash)
|
79
|
+
obj["_id"] = primary_key
|
80
|
+
else
|
81
|
+
@log.fatal "WOAH! Class: #{object.class} Value: #{object}"
|
82
|
+
return
|
83
|
+
end
|
84
|
+
|
85
|
+
|
86
|
+
if self.has_key? primary_key
|
87
|
+
@collection.update({"_id" => primary_key}, obj)
|
88
|
+
else
|
89
|
+
@collection.insert obj
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
def [] primary_key
|
95
|
+
check_key primary_key
|
96
|
+
|
97
|
+
doc = @collection.find("_id" => primary_key).to_a[0]
|
98
|
+
|
99
|
+
#
|
100
|
+
# Delete the "_id" from the document as it is artificial for the MongoDB primary key
|
101
|
+
doc.delete("_id")
|
102
|
+
|
103
|
+
Crack::JSON.parse(doc.to_json)
|
104
|
+
end
|
105
|
+
|
106
|
+
def has_key?(primary_key)
|
107
|
+
check_key primary_key
|
108
|
+
|
109
|
+
doc = @collection.find "_id" => primary_key
|
110
|
+
if doc.count == 0
|
111
|
+
false
|
112
|
+
else
|
113
|
+
true
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def each
|
118
|
+
|
119
|
+
collection = @mongo.collection(@collection_name)
|
120
|
+
|
121
|
+
collection.find.each do |row|
|
122
|
+
yield row["_id"], row.to_json
|
123
|
+
end
|
124
|
+
|
125
|
+
end
|
126
|
+
|
127
|
+
def flush
|
128
|
+
end
|
129
|
+
|
130
|
+
private
|
131
|
+
|
132
|
+
def check_key(primary_key)
|
133
|
+
# Raise an exception here if the key must conform to a specific format
|
134
|
+
# Example: raise "key must be a string object" unless key.is_a? String
|
135
|
+
end
|
136
|
+
|
137
|
+
def check_object(object)
|
138
|
+
raise "#{object.class} must implement the to_json method" unless object.respond_to? :to_json
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require "mongo"
|
2
|
+
require "logger"
|
3
|
+
|
4
|
+
module BarnyardHarvester
|
5
|
+
class MongoDbHelper
|
6
|
+
|
7
|
+
def self.connect(args)
|
8
|
+
|
9
|
+
@debug = args.fetch(:debug) { false }
|
10
|
+
@log = args.fetch(:logger) { Logger.new(STDOUT) }
|
11
|
+
|
12
|
+
@log.debug "Connection parameters #{args[:host]} db: #{args[:db]} collection: #{args[:collection]}" if @debug
|
13
|
+
|
14
|
+
# Connect to Mongo
|
15
|
+
if args.has_key? :host
|
16
|
+
if args[:host].is_a? Array
|
17
|
+
@log.debug "Connecting to replica set #{args[:host]}"
|
18
|
+
@mongo = Mongo::ReplSetConnection.new(args[:host]).db(args[:db])
|
19
|
+
else
|
20
|
+
@log.debug "Connecting to single host #{args[:host]}"
|
21
|
+
@mongo = Mongo::Connection.new(args[:host].split(":")[0], args[:host].split(":")[1]).db(args[:db])
|
22
|
+
end
|
23
|
+
else
|
24
|
+
@log.info "Connecting to localhost #{args[:host]}"
|
25
|
+
@mongo = Mongo::Connection.new.db(args[:db])
|
26
|
+
end
|
27
|
+
|
28
|
+
#db = @mongo.db((mongo_args[:db])
|
29
|
+
#auth = db.authenticate
|
30
|
+
|
31
|
+
unless args[:user].to_s == ''
|
32
|
+
@log.debug "Authenticating as #{args[:user]}"
|
33
|
+
@mongo.authenticate(args[:user], args[:password])
|
34
|
+
end
|
35
|
+
|
36
|
+
@mongo
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
if __FILE__ == $0
|
42
|
+
|
43
|
+
mongo_replica_set = Array.new
|
44
|
+
|
45
|
+
mongo_replica_set << "ip-172-19-31-44.c.qaapollogrp.edu:27017"
|
46
|
+
mongo_replica_set << "ip-172-19-30-49.c.qaapollogrp.edu:27017"
|
47
|
+
mongo_replica_set << "ip-172-19-31-202.c.qaapollogrp.edu:27017"
|
48
|
+
|
49
|
+
mongo_args = Hash.new
|
50
|
+
# mongo_args[:host] = "localhost:27017"
|
51
|
+
mongo_args[:host] = mongo_replica_set
|
52
|
+
mongo_args[:db] = "aws"
|
53
|
+
mongo_args[:collection] = "test_collection"
|
54
|
+
mongo_args[:user] = "honeybadger"
|
55
|
+
mongo_args[:password] = "0joQuk35vJM05Hj"
|
56
|
+
|
57
|
+
mongo_args[:debug] = true
|
58
|
+
|
59
|
+
my_log = Logger.new(STDOUT)
|
60
|
+
|
61
|
+
mongo_args[:logger] = my_log
|
62
|
+
|
63
|
+
s = ApolMongo::MongoHelper.connect mongo_args
|
64
|
+
|
65
|
+
c = s.collection(mongo_args[:collection])
|
66
|
+
|
67
|
+
|
68
|
+
c.find.each do |row|
|
69
|
+
puts row
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
module BarnyardHarvester
|
2
|
+
|
3
|
+
class ChangeLogs
|
4
|
+
@queue = :logs_change
|
5
|
+
end
|
6
|
+
|
7
|
+
class Queue
|
8
|
+
|
9
|
+
class ResqueQueue
|
10
|
+
def initialize(queue, queued_at, harvester_uuid, crop_change_uuid, crop_number, primary_key, transaction_type, value, old_value)
|
11
|
+
Resque.enqueue(queue, queued_at, harvester_uuid, crop_change_uuid, crop_number, primary_key, transaction_type, value, old_value)
|
12
|
+
Resque.enqueue(ChangeLogs,queued_at, harvester_uuid, crop_change_uuid, crop_number, primary_key, transaction_type, value, old_value)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def initialize(args)
|
17
|
+
|
18
|
+
@debug = args.fetch(:debug) { false }
|
19
|
+
@log = args.fetch(:logger) { Logger.new(STDOUT) }
|
20
|
+
|
21
|
+
raise "arguments must contain :crop_number => some_integer" if args[:crop_number].nil?
|
22
|
+
|
23
|
+
resque_class_name = "Distribute"
|
24
|
+
|
25
|
+
# If the class does not exist, the rescue block will create it.
|
26
|
+
# The Class Queue is inherited by the AddQueue, ChangeQueue and DeleteQueue, but
|
27
|
+
# we only want to create one "resque" queue for this instantiation
|
28
|
+
begin
|
29
|
+
Object.const_get(resque_class_name)
|
30
|
+
rescue
|
31
|
+
# Set the queue name to this apol_harvester's id prefixed with a Q_
|
32
|
+
#Object.const_set(resque_class_name, Class.new { @queue = "Q_#{args[:crop_number]}"})
|
33
|
+
Object.const_set(resque_class_name, Class.new { @queue = "Farmer"})
|
34
|
+
end
|
35
|
+
|
36
|
+
@resque_queue = Object.const_get(resque_class_name)
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
def push(harvester_uuid, crop_change_uuid, crop_number, primary_key, transaction_type, value, old_value=Hash.new)
|
41
|
+
check_key primary_key
|
42
|
+
|
43
|
+
ResqueQueue.new(@resque_queue, DateTime.now, harvester_uuid, crop_change_uuid, crop_number, primary_key, transaction_type, value.to_json, old_value.to_json)
|
44
|
+
|
45
|
+
message = "RedisQueue: #{@resque_queue}, Now: #{DateTime.now}, Harvester:#{harvester_uuid}, Change:#{crop_change_uuid} crop_number: #{crop_number}, key: #{primary_key}, transaction_type: #{transaction_type})"
|
46
|
+
|
47
|
+
if @log.level == Logger::DEBUG
|
48
|
+
message += ", value: #{value.to_json}, old_value: #{old_value.to_json}"
|
49
|
+
@log.debug message
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# Flush any data if needed.
|
54
|
+
#
|
55
|
+
def flush
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
# Raise an exception here if the key must conform to a specific format
|
61
|
+
#
|
62
|
+
def check_key(primary_key)
|
63
|
+
# Example: raise "key must be a string object" unless key.is_a? String
|
64
|
+
primary_key
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
# AddQueue
|
70
|
+
#
|
71
|
+
class AddQueue < Queue
|
72
|
+
end
|
73
|
+
|
74
|
+
# ChangeQueue
|
75
|
+
#
|
76
|
+
class ChangeQueue < Queue
|
77
|
+
end
|
78
|
+
|
79
|
+
# DeleteQueue
|
80
|
+
#
|
81
|
+
class DeleteQueue < Queue
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require "rspec"
|
2
|
+
require "./lib/barnyard_harvester/mongodb_helper"
|
3
|
+
|
4
|
+
describe BarnyardHarvester::MongoDbHelper do
|
5
|
+
|
6
|
+
it "should connect to a replica set" do
|
7
|
+
|
8
|
+
mongo_replica_set = Array.new
|
9
|
+
|
10
|
+
mongo_replica_set << "ip-172-19-31-44.c.qaapollogrp.edu:27017"
|
11
|
+
mongo_replica_set << "ip-172-19-30-49.c.qaapollogrp.edu:27017"
|
12
|
+
mongo_replica_set << "ip-172-19-31-202.c.qaapollogrp.edu:27017"
|
13
|
+
mongo_args = Hash.new
|
14
|
+
|
15
|
+
|
16
|
+
mongo_args[:host] = mongo_replica_set
|
17
|
+
mongo_args[:db] = "aws"
|
18
|
+
mongo_args[:collection] = "test_collection"
|
19
|
+
mongo_args[:user] = "honeybadger"
|
20
|
+
mongo_args[:password] = "0joQuk35vJM05Hj"
|
21
|
+
|
22
|
+
mongo_args[:debug] = true
|
23
|
+
|
24
|
+
my_log = Logger.new(STDOUT)
|
25
|
+
|
26
|
+
mongo_args[:logger] = my_log
|
27
|
+
|
28
|
+
s = BarnyardHarvester::MongoDbHelper.connect mongo_args
|
29
|
+
|
30
|
+
c = s.collection(mongo_args[:collection])
|
31
|
+
|
32
|
+
c.find.each do |row|
|
33
|
+
puts row
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should connect to one server" do
|
39
|
+
|
40
|
+
mongo_args = Hash.new
|
41
|
+
mongo_args[:host] = "localhost:27017"
|
42
|
+
mongo_args[:db] = "aws"
|
43
|
+
mongo_args[:collection] = "test_collection"
|
44
|
+
|
45
|
+
mongo_args[:debug] = true
|
46
|
+
|
47
|
+
my_log = Logger.new(STDOUT)
|
48
|
+
|
49
|
+
mongo_args[:logger] = my_log
|
50
|
+
|
51
|
+
s = BarnyardHarvester::MongoDbHelper.connect mongo_args
|
52
|
+
|
53
|
+
c = s.collection(mongo_args[:collection])
|
54
|
+
|
55
|
+
c.find.each do |row|
|
56
|
+
puts row
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
data/spec/mongo_spec.rb
ADDED
@@ -0,0 +1,180 @@
|
|
1
|
+
require "barnyard_harvester"
|
2
|
+
require "yaml"
|
3
|
+
require "mongo"
|
4
|
+
require "redis"
|
5
|
+
require "logger"
|
6
|
+
require "json"
|
7
|
+
|
8
|
+
CROP_NUMBER = 1
|
9
|
+
|
10
|
+
REDIS_SETTINGS = {
|
11
|
+
:host => "localhost",
|
12
|
+
:port => 6379,
|
13
|
+
:db => CROP_NUMBER
|
14
|
+
}
|
15
|
+
|
16
|
+
MONGODB_SETTINGS = {
|
17
|
+
:host => "localhost",
|
18
|
+
:collection => "test_collection",
|
19
|
+
:db => "test_database",
|
20
|
+
:collection => "test_collection"
|
21
|
+
}
|
22
|
+
|
23
|
+
MONGODB_REPLICA_SET_SETTINGS = {
|
24
|
+
:host => ["ip-172-19-31-44.c.qaapollogrp.edu:27017", "ip-172-19-30-49.c.qaapollogrp.edu:27017", "ip-172-19-31-202.c.qaapollogrp.edu:27017"],
|
25
|
+
:collection => "test_collection",
|
26
|
+
:db => "test_database",
|
27
|
+
:user => "honeybadger",
|
28
|
+
:password => "0joQuk35vJM05Hj",
|
29
|
+
:collection => "test_collection"
|
30
|
+
}
|
31
|
+
|
32
|
+
$mongo_settings = MONGODB_REPLICA_SET_SETTINGS
|
33
|
+
|
34
|
+
describe BarnyardHarvester do
|
35
|
+
|
36
|
+
def load_and_process_file(file, backend)
|
37
|
+
|
38
|
+
data = YAML::load_file file
|
39
|
+
|
40
|
+
my_logger = Logger.new(STDOUT)
|
41
|
+
my_logger.level = Logger::INFO
|
42
|
+
|
43
|
+
h = BarnyardHarvester::Sync.new(:backend => backend, :debug => false, :mongodb_settings => $mongo_settings, :crop_number => CROP_NUMBER, :redis_settings => REDIS_SETTINGS, :logger => my_logger)
|
44
|
+
|
45
|
+
h.run do
|
46
|
+
data.each do |primary_key, value|
|
47
|
+
h.process primary_key, value
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
h
|
52
|
+
end
|
53
|
+
|
54
|
+
def flush
|
55
|
+
|
56
|
+
require "barnyard_harvester/mongodb_helper"
|
57
|
+
|
58
|
+
my_logger = Logger.new(STDOUT)
|
59
|
+
my_logger.level = Logger::INFO
|
60
|
+
|
61
|
+
mongo = BarnyardHarvester::MongoDbHelper.connect $mongo_settings.merge(logger: my_logger)
|
62
|
+
collection_name = $mongo_settings[:collection]
|
63
|
+
collection = mongo.collection(collection_name)
|
64
|
+
|
65
|
+
collection.find.each do |row|
|
66
|
+
collection.remove("_id" => row["_id"])
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
before(:each) do
|
72
|
+
|
73
|
+
flush
|
74
|
+
|
75
|
+
@crop_number = 1
|
76
|
+
|
77
|
+
file = "spec/fixtures/data-init.yml"
|
78
|
+
|
79
|
+
data = YAML::load_file file
|
80
|
+
|
81
|
+
h = load_and_process_file(file, :mongodb)
|
82
|
+
|
83
|
+
h.add_count.should eq(data.count)
|
84
|
+
h.delete_count.should eq(0)
|
85
|
+
h.change_count.should eq(0)
|
86
|
+
h.source_count.should eq(data.count)
|
87
|
+
h.cache_count.should eq(data.count)
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
it "test initial load of records" do
|
92
|
+
|
93
|
+
data = YAML::load_file "spec/fixtures/data-init.yml"
|
94
|
+
|
95
|
+
mongo = BarnyardHarvester::MongoDbHelper.connect $mongo_settings
|
96
|
+
collection = mongo.collection($mongo_settings[:collection])
|
97
|
+
|
98
|
+
data.each do |primary_key, value|
|
99
|
+
|
100
|
+
doc = collection.find("_id" => primary_key).to_a[0]
|
101
|
+
|
102
|
+
doc.delete("_id")
|
103
|
+
|
104
|
+
value.should eq(doc)
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
|
109
|
+
it "test add one record" do
|
110
|
+
|
111
|
+
file = "spec/fixtures/data-add.yml"
|
112
|
+
data = YAML::load_file file
|
113
|
+
|
114
|
+
h = load_and_process_file(file, :mongodb)
|
115
|
+
|
116
|
+
h.add_count.should eq(1)
|
117
|
+
h.delete_count.should eq(0)
|
118
|
+
h.change_count.should eq(0)
|
119
|
+
h.source_count.should eq(data.count)
|
120
|
+
h.cache_count.should eq(data.count)
|
121
|
+
|
122
|
+
end
|
123
|
+
|
124
|
+
it "test change one record" do
|
125
|
+
|
126
|
+
file = "spec/fixtures/data-change.yml"
|
127
|
+
|
128
|
+
data = YAML::load_file file
|
129
|
+
|
130
|
+
h = load_and_process_file(file, :mongodb)
|
131
|
+
|
132
|
+
h.add_count.should eq(0)
|
133
|
+
h.delete_count.should eq(0)
|
134
|
+
h.change_count.should eq(1)
|
135
|
+
h.source_count.should eq(data.count)
|
136
|
+
h.cache_count.should eq(data.count)
|
137
|
+
|
138
|
+
end
|
139
|
+
|
140
|
+
it "test delete one record" do
|
141
|
+
|
142
|
+
file = "spec/fixtures/data-delete.yml"
|
143
|
+
|
144
|
+
data = YAML::load_file file
|
145
|
+
|
146
|
+
h = load_and_process_file(file, :mongodb)
|
147
|
+
|
148
|
+
|
149
|
+
h.add_count.should eq(0)
|
150
|
+
h.delete_count.should eq(1)
|
151
|
+
h.change_count.should eq(0)
|
152
|
+
h.source_count.should eq(data.count)
|
153
|
+
h.cache_count.should eq(data.count + 1)
|
154
|
+
|
155
|
+
end
|
156
|
+
|
157
|
+
it "test delete all records and add one" do
|
158
|
+
|
159
|
+
init_file = "spec/fixtures/data-init.yml"
|
160
|
+
init_data = YAML::load_file init_file
|
161
|
+
|
162
|
+
file = "spec/fixtures/data-delete-all-records-add-one.yml"
|
163
|
+
#data = YAML::load_file file
|
164
|
+
|
165
|
+
h = load_and_process_file(file, :mongodb)
|
166
|
+
|
167
|
+
h.add_count.should eq(1)
|
168
|
+
h.delete_count.should eq(5)
|
169
|
+
h.change_count.should eq(0)
|
170
|
+
h.source_count.should eq(1)
|
171
|
+
h.cache_count.should eq(init_data.count + 1)
|
172
|
+
|
173
|
+
end
|
174
|
+
|
175
|
+
|
176
|
+
after(:each) do
|
177
|
+
end
|
178
|
+
|
179
|
+
|
180
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: barnyard_harvester
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-11-
|
12
|
+
date: 2012-11-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &70118633756900 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70118633756900
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: resque
|
27
|
-
requirement: &
|
27
|
+
requirement: &70118633753220 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70118633753220
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: crack
|
38
|
-
requirement: &
|
38
|
+
requirement: &70118633748400 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70118633748400
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: json
|
49
|
-
requirement: &
|
49
|
+
requirement: &70118633735240 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70118633735240
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: uuid
|
60
|
-
requirement: &
|
60
|
+
requirement: &70118633729920 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,7 +65,29 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :runtime
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70118633729920
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: bson_ext
|
71
|
+
requirement: &70118633723020 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - =
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: 1.6.0
|
77
|
+
type: :runtime
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *70118633723020
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: mongo
|
82
|
+
requirement: &70118633718980 !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - =
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: 1.6.0
|
88
|
+
type: :runtime
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: *70118633718980
|
69
91
|
description: Performs harvests on data sources and detects adds, changes and deletes.
|
70
92
|
email:
|
71
93
|
- supercoder@gmail.com
|
@@ -85,6 +107,9 @@ files:
|
|
85
107
|
- lib/barnyard_harvester.rb
|
86
108
|
- lib/barnyard_harvester/hash.rb
|
87
109
|
- lib/barnyard_harvester/hash_queue.rb
|
110
|
+
- lib/barnyard_harvester/mongodb.rb
|
111
|
+
- lib/barnyard_harvester/mongodb_helper.rb
|
112
|
+
- lib/barnyard_harvester/mongodb_queue.rb
|
88
113
|
- lib/barnyard_harvester/redis.rb
|
89
114
|
- lib/barnyard_harvester/redis_queue.rb
|
90
115
|
- lib/barnyard_harvester/version.rb
|
@@ -96,6 +121,8 @@ files:
|
|
96
121
|
- spec/fixtures/data-init.yml
|
97
122
|
- spec/hash_spec.rb
|
98
123
|
- spec/loader_spec.rb
|
124
|
+
- spec/mongo_helper_spec.rb
|
125
|
+
- spec/mongo_spec.rb
|
99
126
|
- spec/redis_spec.rb
|
100
127
|
- spec/spec_helper.rb
|
101
128
|
homepage: https://github.com/jongillies/barnyard/tree/master/barnyard_harvester
|
@@ -118,7 +145,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
118
145
|
version: '0'
|
119
146
|
requirements: []
|
120
147
|
rubyforge_project: barnyard_harvester
|
121
|
-
rubygems_version: 1.8.
|
148
|
+
rubygems_version: 1.8.15
|
122
149
|
signing_key:
|
123
150
|
specification_version: 3
|
124
151
|
summary: Please check the README.md for more information.
|
@@ -130,5 +157,7 @@ test_files:
|
|
130
157
|
- spec/fixtures/data-init.yml
|
131
158
|
- spec/hash_spec.rb
|
132
159
|
- spec/loader_spec.rb
|
160
|
+
- spec/mongo_helper_spec.rb
|
161
|
+
- spec/mongo_spec.rb
|
133
162
|
- spec/redis_spec.rb
|
134
163
|
- spec/spec_helper.rb
|