barnyard_market 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -24,6 +24,7 @@ Gem::Specification.new do |gem|
24
24
  gem.add_runtime_dependency "barnyard_harvester"
25
25
  gem.add_runtime_dependency "crack"
26
26
  gem.add_runtime_dependency "uuid"
27
+ gem.add_runtime_dependency "bunny"
27
28
 
28
29
 
29
30
  end
@@ -1,3 +1,3 @@
1
1
  module BarnyardMarket
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -5,8 +5,10 @@ require "crack"
5
5
  require "aws-sdk"
6
6
  require "uuid"
7
7
  require "json"
8
+ require "bunny"
8
9
 
9
10
  module BarnyardMarket
11
+
10
12
  class ProcessSubscriptions
11
13
 
12
14
  def initialize(args)
@@ -14,30 +16,25 @@ module BarnyardMarket
14
16
  @debug = args.fetch(:debug) { false }
15
17
  @log = args.fetch(:logger) { Logger.new(STDOUT) }
16
18
 
17
- @sqs_settings = args.fetch(:sqs_settings) { raise "You must provide :sqs_settings" }
18
- @dynamodb_settings = args.fetch(:dynamodb_settings) { raise "You must provide :dynamodb_settings" }
19
19
  @cachecow_settings = args.fetch(:cachecow_settings) { raise "You must provide :cachecow_settings" }
20
20
 
21
21
  @cachecow = BarnyardCcfeeder::CacheCow.new(@cachecow_settings)
22
22
 
23
- @sqs = AWS::SQS.new(@sqs_settings)
24
-
25
- @farmer_queue = @sqs.queues.create("barnyard-farmer")
26
- @transaction_queue = @sqs.queues.create("barnyard-transactions")
23
+ @q = BarnyardHarvester::GenericQueue.new(args)
27
24
 
28
25
  deliver_subscriptions
29
26
  end
30
27
 
31
-
32
28
  def deliver_subscriptions
33
29
 
34
30
  count = 0
35
31
 
36
- while (msg = @farmer_queue.receive_message) do
32
+
33
+ while (msg = @q.pop("barnyard-farmer")) do
37
34
 
38
35
  count += 1
39
36
 
40
- payload = Crack::JSON.parse(msg.body)
37
+ payload = Crack::JSON.parse(msg)
41
38
 
42
39
  @log.info "#{count} Received #{payload["transaction_type"].upcase} for crop #{payload["crop_number"]}"
43
40
 
@@ -48,18 +45,17 @@ module BarnyardMarket
48
45
  subscribed.each do |subscription|
49
46
 
50
47
  queue_name = "barnyard-transactions-subscriber-#{subscription["subscriber"]["id"]}-crop-#{subscription["crop"]["crop_number"]}"
51
- queue = @sqs.queues.create(queue_name)
52
48
 
53
49
  payload["subscription_id"] = subscription["id"]
54
50
  payload["transaction_uuid"] = UUID.new.generate
55
51
 
56
52
  @log.info "Sending message for change #{payload["change_uuid"]} to queue #{queue_name}"
57
53
  json_payload = payload.to_json
58
- queue.send_message(json_payload)
59
- @transaction_queue.send_message(json_payload)
60
- end
61
54
 
62
- msg.delete
55
+ @q.push(queue_name, json_payload)
56
+ @q.push("barnyard-transaction", json_payload)
57
+
58
+ end
63
59
 
64
60
  end
65
61
 
data/spec/market_spec.rb CHANGED
@@ -1,18 +1,6 @@
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
4
  ["BACKEND_AWS_SECRET_ACCESS_KEY",
17
5
  "BACKEND_AWS_ACCESS_KEY_ID",
18
6
  "BACKEND_AWS_REGION",
@@ -36,28 +24,49 @@ SQS_SETTINGS = {
36
24
  :secret_access_key => BACKEND_AWS_SECRET_ACCESS_KEY
37
25
  }
38
26
 
27
+ REDIS_SETTINGS = {
28
+ :host => "localhost",
29
+ :port => 6379,
30
+ }
31
+
32
+ RABBITMQ_SETTINGS = {
33
+ :host => "localhost"
34
+ # :port => 6163
35
+ }
36
+
39
37
  CACHECOW_SETTINGS = {
40
38
  #:url => "http://localhost:3000"
41
39
  :url => "https://cachecow.c.qaapollogrp.edu"
42
40
  }
43
41
 
44
- describe "i should" do
42
+ describe "Distributor" do
45
43
 
46
- it "should work" do
44
+ it "should empty the RabbitMQ Farmer" do
47
45
 
48
46
  my_logger = Logger.new(STDOUT)
49
47
  my_logger.level = Logger::DEBUG
50
48
 
51
- h = BarnyardMarket::ProcessSubscriptions.new(:queueing => :sqs,
52
- :sqs_settings => SQS_SETTINGS,
53
- :backend => :dynamodb,
49
+ h = BarnyardMarket::ProcessSubscriptions.new(:queueing => :rabbitmq,
50
+ :rabbitmq_settings => RABBITMQ_SETTINGS,
51
+ :backend => :redis,
54
52
  :debug => true,
55
- :dynamodb_settings => DYNAMODB_SETTINGS,
56
53
  :cachecow_settings => CACHECOW_SETTINGS,
57
54
  :logger => my_logger)
58
55
 
56
+ end
57
+
58
+ it "should empty the SQS Farmer" do
59
59
 
60
- #To change this template use File | Settings | File Templates.
61
- true.should == true
60
+ my_logger = Logger.new(STDOUT)
61
+ my_logger.level = Logger::DEBUG
62
+
63
+ h = BarnyardMarket::ProcessSubscriptions.new(:queueing => :sqs,
64
+ :sqs_settings => SQS_SETTINGS,
65
+ :backend => :redis,
66
+ :debug => true,
67
+ :redis_settings => REDIS_SETTINGS,
68
+ :cachecow_settings => CACHECOW_SETTINGS,
69
+ :logger => my_logger)
62
70
  end
71
+
63
72
  end
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.6
4
+ version: 0.0.7
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-30 00:00:00.000000000 Z
12
+ date: 2012-12-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70224690969660 !ruby/object:Gem::Requirement
16
+ requirement: &70111117644060 !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: *70224690969660
24
+ version_requirements: *70111117644060
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: aws-sdk
27
- requirement: &70224690968780 !ruby/object:Gem::Requirement
27
+ requirement: &70111117642800 !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: *70224690968780
35
+ version_requirements: *70111117642800
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: barnyard_ccfeeder
38
- requirement: &70224690967940 !ruby/object:Gem::Requirement
38
+ requirement: &70111117641660 !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: *70224690967940
46
+ version_requirements: *70111117641660
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: barnyard_harvester
49
- requirement: &70224690967060 !ruby/object:Gem::Requirement
49
+ requirement: &70111121753580 !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: *70224690967060
57
+ version_requirements: *70111121753580
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: crack
60
- requirement: &70224690966520 !ruby/object:Gem::Requirement
60
+ requirement: &70111121751680 !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: *70224690966520
68
+ version_requirements: *70111121751680
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: uuid
71
- requirement: &70224690966100 !ruby/object:Gem::Requirement
71
+ requirement: &70111121748100 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,7 +76,18 @@ dependencies:
76
76
  version: '0'
77
77
  type: :runtime
78
78
  prerelease: false
79
- version_requirements: *70224690966100
79
+ version_requirements: *70111121748100
80
+ - !ruby/object:Gem::Dependency
81
+ name: bunny
82
+ requirement: &70111121746980 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :runtime
89
+ prerelease: false
90
+ version_requirements: *70111121746980
80
91
  description: Deliver subscriptions to queues.
81
92
  email:
82
93
  - supercoder@gmail.com