barnyard_market 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/.rvmrc +1 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/barnyard_market.gemspec +29 -0
- data/lib/barnyard_market.rb +62 -0
- data/lib/barnyard_market/version.rb +3 -0
- data/spec/market_spec.rb +39 -0
- data/spec/spec_helper.rb +17 -0
- metadata +124 -0
data/.gitignore
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use ruby-1.9.3-p125@barnyard
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Jon Gillies
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# BarnyardMarket
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'barnyard_market'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install barnyard_market
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/barnyard_market/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Jon Gillies"]
|
6
|
+
gem.email = ["supercoder@gmail.com"]
|
7
|
+
gem.description = %q{Deliver subscriptions to queues.}
|
8
|
+
gem.summary = %q{Help}
|
9
|
+
gem.homepage = "https://github.com/jongillies/barnyard/tree/master/barnyard_market"
|
10
|
+
|
11
|
+
gem.rubyforge_project = "barnyard_market"
|
12
|
+
|
13
|
+
gem.files = `git ls-files`.split($\)
|
14
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
15
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
16
|
+
gem.name = "barnyard_market"
|
17
|
+
gem.require_paths = ["lib"]
|
18
|
+
gem.version = BarnyardMarket::VERSION
|
19
|
+
|
20
|
+
# specify any dependencies here; for example:
|
21
|
+
gem.add_development_dependency "rspec"
|
22
|
+
gem.add_runtime_dependency "aws-sdk"
|
23
|
+
gem.add_runtime_dependency "barnyard_ccfeeder"
|
24
|
+
gem.add_runtime_dependency "barnyard_harvester"
|
25
|
+
gem.add_runtime_dependency "crack"
|
26
|
+
gem.add_runtime_dependency "uuid"
|
27
|
+
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require "barnyard_market/version"
|
2
|
+
require "barnyard_ccfeeder"
|
3
|
+
require "barnyard_harvester"
|
4
|
+
require "crack"
|
5
|
+
require "aws-sdk"
|
6
|
+
require "uuid"
|
7
|
+
require "json"
|
8
|
+
|
9
|
+
module BarnyardMarket
|
10
|
+
class ProcessSubscriptions
|
11
|
+
|
12
|
+
def initialize(args)
|
13
|
+
|
14
|
+
@debug = args.fetch(:debug) { false }
|
15
|
+
@log = args.fetch(:logger) { Logger.new(STDOUT) }
|
16
|
+
|
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
|
+
@cachecow_settings = args.fetch(:cachecow_settings) { raise "You must provide :cachecow_settings" }
|
20
|
+
|
21
|
+
@cachecow = BarnyardCcfeeder::CacheCow.new(@cachecow_settings)
|
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")
|
27
|
+
|
28
|
+
deliver_subscriptions
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
def deliver_subscriptions
|
33
|
+
|
34
|
+
while (msg = @farmer_queue.receive_message) do
|
35
|
+
|
36
|
+
payload = Crack::JSON.parse(msg.body)
|
37
|
+
|
38
|
+
@log.info "Received #{payload["transaction_type"].upcase} for crop #{payload["crop_number"]}"
|
39
|
+
|
40
|
+
subscribed = @cachecow.has_subscribers(payload["crop_number"])
|
41
|
+
|
42
|
+
@log.info "#{subscribed.count} subscriptions for crop #{payload["crop_number"]}"
|
43
|
+
|
44
|
+
subscribed.each do |s|
|
45
|
+
queue_name = "barnyard-transactions-subscriber-#{s["id"]}-crop-#{payload["crop_number"]}"
|
46
|
+
queue = @sqs.queues.create(queue_name)
|
47
|
+
|
48
|
+
payload["subscriber"] = s["id"]
|
49
|
+
payload["transaction_uuid"] = UUID.new.generate
|
50
|
+
|
51
|
+
@log.info "Sending message to queue #{queue_name} for subscriber #{s["id"]} for crop #{payload["crop_number"]}"
|
52
|
+
json_payload = payload.to_json
|
53
|
+
queue.send_message(json_payload)
|
54
|
+
@transaction_queue.send_message(json_payload)
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
data/spec/market_spec.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require "rspec"
|
2
|
+
require "barnyard_market"
|
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
|
+
CACHECOW_SETTINGS = {
|
17
|
+
:url => "http://localhost:3000"
|
18
|
+
}
|
19
|
+
|
20
|
+
describe "i should" do
|
21
|
+
|
22
|
+
it "should work" do
|
23
|
+
|
24
|
+
my_logger = Logger.new(STDOUT)
|
25
|
+
my_logger.level = Logger::DEBUG
|
26
|
+
|
27
|
+
h = BarnyardMarket::ProcessSubscriptions.new(:queueing => :sqs,
|
28
|
+
:sqs_settings => SQS_SETTINGS,
|
29
|
+
:backend => :dynamodb,
|
30
|
+
:debug => true,
|
31
|
+
:dynamodb_settings => DYNAMODB_SETTINGS,
|
32
|
+
:cachecow_settings => CACHECOW_SETTINGS,
|
33
|
+
:logger => my_logger)
|
34
|
+
|
35
|
+
|
36
|
+
#To change this template use File | Settings | File Templates.
|
37
|
+
true.should == true
|
38
|
+
end
|
39
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
9
|
+
config.run_all_when_everything_filtered = true
|
10
|
+
config.filter_run :focus
|
11
|
+
|
12
|
+
# Run specs in random order to surface order dependencies. If you find an
|
13
|
+
# order dependency and want to debug it, you can fix the order by providing
|
14
|
+
# the seed, which is printed after each run.
|
15
|
+
# --seed 1234
|
16
|
+
config.order = 'random'
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: barnyard_market
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jon Gillies
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-11-28 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: &70127165608920 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70127165608920
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: aws-sdk
|
27
|
+
requirement: &70127165605900 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70127165605900
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: barnyard_ccfeeder
|
38
|
+
requirement: &70127165931300 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70127165931300
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: barnyard_harvester
|
49
|
+
requirement: &70127165930880 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :runtime
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70127165930880
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: crack
|
60
|
+
requirement: &70127165930460 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
type: :runtime
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *70127165930460
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: uuid
|
71
|
+
requirement: &70127165930040 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :runtime
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *70127165930040
|
80
|
+
description: Deliver subscriptions to queues.
|
81
|
+
email:
|
82
|
+
- supercoder@gmail.com
|
83
|
+
executables: []
|
84
|
+
extensions: []
|
85
|
+
extra_rdoc_files: []
|
86
|
+
files:
|
87
|
+
- .gitignore
|
88
|
+
- .rvmrc
|
89
|
+
- Gemfile
|
90
|
+
- LICENSE
|
91
|
+
- README.md
|
92
|
+
- Rakefile
|
93
|
+
- barnyard_market.gemspec
|
94
|
+
- lib/barnyard_market.rb
|
95
|
+
- lib/barnyard_market/version.rb
|
96
|
+
- spec/market_spec.rb
|
97
|
+
- spec/spec_helper.rb
|
98
|
+
homepage: https://github.com/jongillies/barnyard/tree/master/barnyard_market
|
99
|
+
licenses: []
|
100
|
+
post_install_message:
|
101
|
+
rdoc_options: []
|
102
|
+
require_paths:
|
103
|
+
- lib
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
+
none: false
|
112
|
+
requirements:
|
113
|
+
- - ! '>='
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
requirements: []
|
117
|
+
rubyforge_project: barnyard_market
|
118
|
+
rubygems_version: 1.8.11
|
119
|
+
signing_key:
|
120
|
+
specification_version: 3
|
121
|
+
summary: Help
|
122
|
+
test_files:
|
123
|
+
- spec/market_spec.rb
|
124
|
+
- spec/spec_helper.rb
|