barnyard_market 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module BarnyardMarket
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -31,40 +31,41 @@ module BarnyardMarket
31
31
 
32
32
  def deliver_subscriptions
33
33
 
34
+ count = 0
35
+
34
36
  while (msg = @farmer_queue.receive_message) do
35
37
 
36
- # begin
37
- payload = Crack::JSON.parse(msg.body)
38
+ count += 1
38
39
 
39
- @log.info "Received #{payload["transaction_type"].upcase} for crop #{payload["crop_number"]}"
40
+ payload = Crack::JSON.parse(msg.body)
40
41
 
41
- subscribed = @cachecow.has_subscribers(payload["crop_number"])
42
+ @log.info "#{count} Received #{payload["transaction_type"].upcase} for crop #{payload["crop_number"]}"
42
43
 
43
- @log.info "#{subscribed.count} subscriptions for crop #{payload["crop_number"]}"
44
+ subscribed = @cachecow.has_subscribers(payload["crop_number"])
44
45
 
45
- subscribed.each do |subscription|
46
+ @log.info "#{subscribed.count} subscriptions for crop #{payload["crop_number"]}"
46
47
 
47
- queue_name = "barnyard-transactions-subscriber-#{subscription["subscriber"]["id"]}-crop-#{subscription["crop"]["crop_number"]}"
48
- queue = @sqs.queues.create(queue_name)
48
+ subscribed.each do |subscription|
49
49
 
50
- payload["subscription_id"] = subscription["id"]
51
- payload["transaction_uuid"] = UUID.new.generate
50
+ queue_name = "barnyard-transactions-subscriber-#{subscription["subscriber"]["id"]}-crop-#{subscription["crop"]["crop_number"]}"
51
+ queue = @sqs.queues.create(queue_name)
52
52
 
53
- @log.info "Sending message for change #{payload["change_uuid"]} to queue #{queue_name}"
54
- json_payload = payload.to_json
55
- queue.send_message(json_payload)
56
- @transaction_queue.send_message(json_payload)
57
- end
53
+ payload["subscription_id"] = subscription["id"]
54
+ payload["transaction_uuid"] = UUID.new.generate
58
55
 
59
- msg.delete
56
+ @log.info "Sending message for change #{payload["change_uuid"]} to queue #{queue_name}"
57
+ json_payload = payload.to_json
58
+ queue.send_message(json_payload)
59
+ @transaction_queue.send_message(json_payload)
60
+ end
60
61
 
61
- # rescue e
62
- # $stderr.puts e
63
- # end
62
+ msg.delete
64
63
 
65
64
  end
66
65
 
67
66
  end
67
+
68
68
  end
69
+
69
70
  end
70
71
 
data/spec/market_spec.rb CHANGED
@@ -1,20 +1,44 @@
1
1
  require "rspec"
2
2
  require "barnyard_market"
3
3
 
4
+ #DYNAMODB_SETTINGS = {
5
+ # :dynamo_db_endpoint => "dynamodb.us-west-1.amazonaws.com",
6
+ # :access_key_id => ENV["AWS_ACCESS_KEY_ID"],
7
+ # :secret_access_key => ENV["AWS_SECRET_ACCESS_KEY"]
8
+ #}
9
+ #
10
+ #SQS_SETTINGS = {
11
+ # :sqs_endpoint => "sqs.us-west-1.amazonaws.com",
12
+ # :access_key_id => ENV["AWS_ACCESS_KEY_ID"],
13
+ # :secret_access_key => ENV["AWS_SECRET_ACCESS_KEY"]
14
+ #}
15
+
16
+ ["BACKEND_AWS_SECRET_ACCESS_KEY",
17
+ "BACKEND_AWS_ACCESS_KEY_ID",
18
+ "BACKEND_AWS_REGION",
19
+ "AWS_SECRET_ACCESS_KEY",
20
+ "AWS_ACCESS_KEY_ID"].each do |env_var|
21
+ eval("#{env_var}=ENV[\"#{env_var}\"]")
22
+ if eval("#{env_var}.nil?")
23
+ raise "You must specify #{env_var} in the environment."
24
+ end
25
+ end
26
+
4
27
  DYNAMODB_SETTINGS = {
5
- :dynamo_db_endpoint => "dynamodb.us-west-1.amazonaws.com",
6
- :access_key_id => ENV["AWS_ACCESS_KEY_ID"],
7
- :secret_access_key => ENV["AWS_SECRET_ACCESS_KEY"]
28
+ :dynamo_db_endpoint => "dynamodb.#{BACKEND_AWS_REGION}.amazonaws.com",
29
+ :access_key_id => BACKEND_AWS_ACCESS_KEY_ID,
30
+ :secret_access_key => BACKEND_AWS_SECRET_ACCESS_KEY
8
31
  }
9
32
 
10
33
  SQS_SETTINGS = {
11
- :sqs_endpoint => "sqs.us-west-1.amazonaws.com",
12
- :access_key_id => ENV["AWS_ACCESS_KEY_ID"],
13
- :secret_access_key => ENV["AWS_SECRET_ACCESS_KEY"]
34
+ :sqs_endpoint => "sqs.#{BACKEND_AWS_REGION}.amazonaws.com",
35
+ :access_key_id => BACKEND_AWS_ACCESS_KEY_ID,
36
+ :secret_access_key => BACKEND_AWS_SECRET_ACCESS_KEY
14
37
  }
15
38
 
16
39
  CACHECOW_SETTINGS = {
17
- :url => "http://localhost:3000"
40
+ #:url => "http://localhost:3000"
41
+ :url => "https://cachecow.c.qaapollogrp.edu"
18
42
  }
19
43
 
20
44
  describe "i should" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: barnyard_market
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-11-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70152213295180 !ruby/object:Gem::Requirement
16
+ requirement: &70224690969660 !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: *70152213295180
24
+ version_requirements: *70224690969660
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: aws-sdk
27
- requirement: &70152213294140 !ruby/object:Gem::Requirement
27
+ requirement: &70224690968780 !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: *70152213294140
35
+ version_requirements: *70224690968780
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: barnyard_ccfeeder
38
- requirement: &70152213293360 !ruby/object:Gem::Requirement
38
+ requirement: &70224690967940 !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: *70152213293360
46
+ version_requirements: *70224690967940
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: barnyard_harvester
49
- requirement: &70152213292540 !ruby/object:Gem::Requirement
49
+ requirement: &70224690967060 !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: *70152213292540
57
+ version_requirements: *70224690967060
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: crack
60
- requirement: &70152213307700 !ruby/object:Gem::Requirement
60
+ requirement: &70224690966520 !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: *70152213307700
68
+ version_requirements: *70224690966520
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: uuid
71
- requirement: &70152213306040 !ruby/object:Gem::Requirement
71
+ requirement: &70224690966100 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,7 +76,7 @@ dependencies:
76
76
  version: '0'
77
77
  type: :runtime
78
78
  prerelease: false
79
- version_requirements: *70152213306040
79
+ version_requirements: *70224690966100
80
80
  description: Deliver subscriptions to queues.
81
81
  email:
82
82
  - supercoder@gmail.com