barnyard_harvester 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +2 -0
- data/lib/barnyard_harvester/hash_queue.rb +2 -2
- data/lib/barnyard_harvester/rabbitmq_queue.rb +5 -5
- data/lib/barnyard_harvester/resque_queue.rb +6 -6
- data/lib/barnyard_harvester/sqs_queue.rb +5 -5
- data/lib/barnyard_harvester/version.rb +1 -1
- data/lib/barnyard_harvester.rb +5 -5
- data/spec/dynamodb_sqs_spec.rb +3 -1
- metadata +21 -21
data/README.md
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
The Harvester gem provides a simple interface where you can iterate your data source and send records to the sync engine. The default backend storage is Redis. Since the workers will use Resque which requires Redis, this make sense to use Redis to cache the data. However, any backend cache can be implemented.
|
4
4
|
|
5
|
+
I've now implemented using DynamoDB for the backend and SQS for the messages.
|
6
|
+
|
5
7
|
Your data sources are called "crops". You must assign a unique integer 1..100 to each crop. This is the integer that is used to create the Redis collection. By default Redis only allows a maximum of 16 databases, so this must be changed if you go above 16.
|
6
8
|
|
7
9
|
WARNING! Do not use crop number 1-9 in production, they are reserved for system testing.
|
@@ -13,12 +13,12 @@ module BarnyardHarvester
|
|
13
13
|
|
14
14
|
end
|
15
15
|
|
16
|
-
def push(harvester_uuid,
|
16
|
+
def push(harvester_uuid, change_uuid, crop_number, primary_key, transaction_type, value, old_value=Hash.new)
|
17
17
|
check_key primary_key
|
18
18
|
|
19
19
|
@queue[primary_key] = value.to_json
|
20
20
|
|
21
|
-
@log.debug "HashQueue: Now: #{DateTime.now}, Harvester:#{harvester_uuid}, Change:#{
|
21
|
+
@log.debug "HashQueue: Now: #{DateTime.now}, Harvester:#{harvester_uuid}, Change:#{change_uuid} crop_number: #{crop_number}, key: #{primary_key}, transaction_type: #{transaction_type})"
|
22
22
|
|
23
23
|
end
|
24
24
|
|
@@ -9,12 +9,12 @@ module BarnyardHarvester
|
|
9
9
|
|
10
10
|
class Queue
|
11
11
|
|
12
|
-
def enqueue(queue, queued_at, harvester_uuid,
|
12
|
+
def enqueue(queue, queued_at, harvester_uuid, change_uuid, crop_number, primary_key, transaction_type, value, old_value)
|
13
13
|
|
14
14
|
payload = Hash.new
|
15
15
|
payload[:queued_at] = queued_at
|
16
16
|
payload[:harvester_uuid] = harvester_uuid
|
17
|
-
payload[:
|
17
|
+
payload[:change_uuid] = change_uuid
|
18
18
|
payload[:crop_number] = crop_number
|
19
19
|
payload[:primary_key] = primary_key
|
20
20
|
payload[:transaction_type] = transaction_type
|
@@ -59,12 +59,12 @@ module BarnyardHarvester
|
|
59
59
|
|
60
60
|
end
|
61
61
|
|
62
|
-
def push(harvester_uuid,
|
62
|
+
def push(harvester_uuid, change_uuid, crop_number, primary_key, transaction_type, value, old_value=Hash.new)
|
63
63
|
check_key primary_key
|
64
64
|
|
65
|
-
enqueue(QUEUE_FARMER, DateTime.now, harvester_uuid,
|
65
|
+
enqueue(QUEUE_FARMER, DateTime.now, harvester_uuid, change_uuid, crop_number, primary_key, transaction_type, value.to_json, old_value.to_json)
|
66
66
|
|
67
|
-
message = "RabbitQueue: #{QUEUE_FARMER}, Now: #{DateTime.now}, Harvester:#{harvester_uuid}, Change:#{
|
67
|
+
message = "RabbitQueue: #{QUEUE_FARMER}, Now: #{DateTime.now}, Harvester:#{harvester_uuid}, Change:#{change_uuid} crop_number: #{crop_number}, key: #{primary_key}, transaction_type: #{transaction_type})"
|
68
68
|
|
69
69
|
if @log.level == Logger::DEBUG
|
70
70
|
message += ", value: #{value.to_json}, old_value: #{old_value.to_json}"
|
@@ -18,9 +18,9 @@ module BarnyardHarvester
|
|
18
18
|
class Queue
|
19
19
|
|
20
20
|
class Enqueue
|
21
|
-
def initialize(queue, queued_at, harvester_uuid,
|
22
|
-
Resque.enqueue(queue, queued_at, harvester_uuid,
|
23
|
-
Resque.enqueue(ChangeLogs, queued_at, harvester_uuid,
|
21
|
+
def initialize(queue, queued_at, harvester_uuid, change_uuid, crop_number, primary_key, transaction_type, value, old_value)
|
22
|
+
Resque.enqueue(queue, queued_at, harvester_uuid, change_uuid, crop_number, primary_key, transaction_type, value, old_value)
|
23
|
+
Resque.enqueue(ChangeLogs, queued_at, harvester_uuid, change_uuid, crop_number, primary_key, transaction_type, value, old_value)
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
@@ -54,12 +54,12 @@ module BarnyardHarvester
|
|
54
54
|
end
|
55
55
|
|
56
56
|
|
57
|
-
def push(harvester_uuid,
|
57
|
+
def push(harvester_uuid, change_uuid, crop_number, primary_key, transaction_type, value, old_value=Hash.new)
|
58
58
|
check_key primary_key
|
59
59
|
|
60
|
-
Enqueue.new(@resque_queue, DateTime.now, harvester_uuid,
|
60
|
+
Enqueue.new(@resque_queue, DateTime.now, harvester_uuid, change_uuid, crop_number, primary_key, transaction_type, value.to_json, old_value.to_json)
|
61
61
|
|
62
|
-
message = "RedisQueue: #{@resque_queue}, Now: #{DateTime.now}, Harvester:#{harvester_uuid}, Change:#{
|
62
|
+
message = "RedisQueue: #{@resque_queue}, Now: #{DateTime.now}, Harvester:#{harvester_uuid}, Change:#{change_uuid} crop_number: #{crop_number}, key: #{primary_key}, transaction_type: #{transaction_type})"
|
63
63
|
|
64
64
|
if @log.level == Logger::DEBUG
|
65
65
|
message += ", value: #{value.to_json}, old_value: #{old_value.to_json}"
|
@@ -9,12 +9,12 @@ module BarnyardHarvester
|
|
9
9
|
|
10
10
|
class Queue
|
11
11
|
|
12
|
-
def enqueue(queued_at, harvester_uuid,
|
12
|
+
def enqueue(queued_at, harvester_uuid, change_uuid, crop_number, primary_key, transaction_type, value, old_value)
|
13
13
|
|
14
14
|
payload = Hash.new
|
15
15
|
payload[:queued_at] = queued_at
|
16
16
|
payload[:harvester_uuid] = harvester_uuid
|
17
|
-
payload[:
|
17
|
+
payload[:change_uuid] = change_uuid
|
18
18
|
payload[:crop_number] = crop_number
|
19
19
|
payload[:primary_key] = primary_key
|
20
20
|
payload[:transaction_type] = transaction_type
|
@@ -65,12 +65,12 @@ module BarnyardHarvester
|
|
65
65
|
|
66
66
|
end
|
67
67
|
|
68
|
-
def push(harvester_uuid,
|
68
|
+
def push(harvester_uuid, change_uuid, crop_number, primary_key, transaction_type, value, old_value=Hash.new)
|
69
69
|
check_key primary_key
|
70
70
|
|
71
|
-
enqueue(DateTime.now, harvester_uuid,
|
71
|
+
enqueue(DateTime.now, harvester_uuid, change_uuid, crop_number, primary_key, transaction_type, value.to_json, old_value.to_json)
|
72
72
|
|
73
|
-
message = "SQS: #{QUEUE_FARMER}, Now: #{DateTime.now}, Harvester:#{harvester_uuid}, Change:#{
|
73
|
+
message = "SQS: #{QUEUE_FARMER}, Now: #{DateTime.now}, Harvester:#{harvester_uuid}, Change:#{change_uuid} crop_number: #{crop_number}, key: #{primary_key}, transaction_type: #{transaction_type})"
|
74
74
|
|
75
75
|
if @log.level == Logger::DEBUG
|
76
76
|
message += ", value: #{value.to_json}, old_value: #{old_value.to_json}"
|
data/lib/barnyard_harvester.rb
CHANGED
@@ -76,8 +76,8 @@ module BarnyardHarvester
|
|
76
76
|
|
77
77
|
# We got delete
|
78
78
|
begin
|
79
|
-
|
80
|
-
@my_delete_queue.push @harvester_uuid,
|
79
|
+
change_uuid = @uuid.generate
|
80
|
+
@my_delete_queue.push @harvester_uuid, change_uuid, @crop_number, primary_key, BarnyardHarvester::DELETE, value
|
81
81
|
rescue Exception => e
|
82
82
|
@log.fatal "FATAL error pushing delete #{primary_key} to queue. #{e}"
|
83
83
|
exit 1
|
@@ -99,7 +99,7 @@ module BarnyardHarvester
|
|
99
99
|
|
100
100
|
@source_count += 1
|
101
101
|
|
102
|
-
|
102
|
+
change_uuid = @uuid.generate
|
103
103
|
|
104
104
|
@key_store[primary_key] = :present # TODO What did this do: if @call_back.nil?
|
105
105
|
|
@@ -114,7 +114,7 @@ module BarnyardHarvester
|
|
114
114
|
if @my_barn[primary_key] != Crack::JSON.parse(value.to_json)
|
115
115
|
#We got change!
|
116
116
|
begin
|
117
|
-
@my_change_queue.push(@harvester_uuid,
|
117
|
+
@my_change_queue.push(@harvester_uuid, change_uuid, @crop_number, primary_key, BarnyardHarvester::CHANGE, value, @my_barn[primary_key])
|
118
118
|
rescue Exception => e
|
119
119
|
@log.fatal "FATAL error pushing change #{primary_key} to queue. #{e}"
|
120
120
|
exit 1
|
@@ -126,7 +126,7 @@ module BarnyardHarvester
|
|
126
126
|
else
|
127
127
|
# We got add!
|
128
128
|
#begin
|
129
|
-
@my_add_queue.push(@harvester_uuid,
|
129
|
+
@my_add_queue.push(@harvester_uuid, change_uuid, @crop_number, primary_key, BarnyardHarvester::ADD, value)
|
130
130
|
#rescue Exception => e
|
131
131
|
# @log.fatal "FATAL error pushing add #{primary_key} to queue. #{e}"
|
132
132
|
# exit 1
|
data/spec/dynamodb_sqs_spec.rb
CHANGED
@@ -4,7 +4,7 @@ require "logger"
|
|
4
4
|
require "json"
|
5
5
|
require "aws-sdk"
|
6
6
|
|
7
|
-
CROP_NUMBER =
|
7
|
+
CROP_NUMBER = 10
|
8
8
|
|
9
9
|
DEFAULT_DYNAMODB_SETTINGS = {
|
10
10
|
:dynamo_db_endpoint => "dynamodb.us-west-1.amazonaws.com",
|
@@ -57,6 +57,8 @@ describe BarnyardHarvester do
|
|
57
57
|
table = db.tables[table_name]
|
58
58
|
table.hash_key = [:id, :string]
|
59
59
|
end
|
60
|
+
|
61
|
+
# TODO AWS::SQS::Errors::QueueDeletedRecently wait 60 seconds and retry
|
60
62
|
table
|
61
63
|
end
|
62
64
|
|
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.9
|
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-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &70360766873440 !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: *70360766873440
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: resque
|
27
|
-
requirement: &
|
27
|
+
requirement: &70360766873020 !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: *70360766873020
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: crack
|
38
|
-
requirement: &
|
38
|
+
requirement: &70360766872600 !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: *70360766872600
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: json
|
49
|
-
requirement: &
|
49
|
+
requirement: &70360766872180 !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: *70360766872180
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: uuid
|
60
|
-
requirement: &
|
60
|
+
requirement: &70360766871760 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :runtime
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70360766871760
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: bson_ext
|
71
|
-
requirement: &
|
71
|
+
requirement: &70360766871260 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - =
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: 1.6.0
|
77
77
|
type: :runtime
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70360766871260
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: mongo
|
82
|
-
requirement: &
|
82
|
+
requirement: &70360766870760 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - =
|
@@ -87,10 +87,10 @@ dependencies:
|
|
87
87
|
version: 1.6.0
|
88
88
|
type: :runtime
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *70360766870760
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: amqp
|
93
|
-
requirement: &
|
93
|
+
requirement: &70360766870380 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - ! '>='
|
@@ -98,10 +98,10 @@ dependencies:
|
|
98
98
|
version: '0'
|
99
99
|
type: :runtime
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *70360766870380
|
102
102
|
- !ruby/object:Gem::Dependency
|
103
103
|
name: aws-sdk
|
104
|
-
requirement: &
|
104
|
+
requirement: &70360766869920 !ruby/object:Gem::Requirement
|
105
105
|
none: false
|
106
106
|
requirements:
|
107
107
|
- - ! '>='
|
@@ -109,7 +109,7 @@ dependencies:
|
|
109
109
|
version: '0'
|
110
110
|
type: :runtime
|
111
111
|
prerelease: false
|
112
|
-
version_requirements: *
|
112
|
+
version_requirements: *70360766869920
|
113
113
|
description: Performs harvests on data sources and detects adds, changes and deletes.
|
114
114
|
email:
|
115
115
|
- supercoder@gmail.com
|
@@ -172,7 +172,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
172
172
|
version: '0'
|
173
173
|
requirements: []
|
174
174
|
rubyforge_project: barnyard_harvester
|
175
|
-
rubygems_version: 1.8.
|
175
|
+
rubygems_version: 1.8.11
|
176
176
|
signing_key:
|
177
177
|
specification_version: 3
|
178
178
|
summary: Please check the README.md for more information.
|