shoryuken 1.0.3 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cbdf9963098403163b107d51bab8dc70384b9d92
4
- data.tar.gz: 97ccedcd84c67dda49c66f96a21899ee5a2ce215
3
+ metadata.gz: ee01f5dc2129537f640aba700e43c8be0f37e77c
4
+ data.tar.gz: 54c1fe1a997a29a77939336ca5f8f2c7e691a745
5
5
  SHA512:
6
- metadata.gz: a323f68eff71aa37fe470239fbcd1c67210200dc999d0d1e34f4b61e68c4da38f745613cf294d0b238708980e555875afa66d713c3ea2649468a39177dc96437
7
- data.tar.gz: 8f7f72e1b4377614e9f7a01c5917b8e0601d59bb8e7669ee2258c7ca8b0adbeeae8f8ea2e5b5130122dcb4b546c671e4f95e295d2dd8bb697cfc0a1fa8a99ff5
6
+ metadata.gz: 5543a21bcfadc457a3bb7444b27ba97d59c9f238bbc9633a100555154823132f7ee6f3cf233f84743ed553cc69a27f8ddf836515690a120b291ffb8212db8783
7
+ data.tar.gz: bcdc762ee9e02366ad4194e372ad76e2e7c23f7e5f15129d8c90d6abfa65af337c4900addaf47d14f8f6578e084a6fd84dad478878589e0c3e2912c5851c89f5
data/CHANGELOG.md ADDED
@@ -0,0 +1,11 @@
1
+ ## [v2.0.0] - 2015-09-22
2
+
3
+ - Allow configuration of SQS/SNS endpoints via environment variables
4
+ - [#130](https://github.com/phstc/shoryuken/pull/130)
5
+
6
+ - Expose queue_name in the message object
7
+ - [#127](https://github.com/phstc/shoryuken/pull/127)
8
+
9
+ - README updates
10
+ - [#122](https://github.com/phstc/shoryuken/pull/122)
11
+ - [#120](https://github.com/phstc/shoryuken/pull/120)
data/README.md CHANGED
@@ -36,7 +36,7 @@ If all queues get empty, all processors will be changed to the waiting state and
36
36
 
37
37
  ### Fetch in batches
38
38
 
39
- To be even more performance and cost efficient, Shoryuken fetches SQS messages in batches, so a single SQS request can fetch up to 10 messages.
39
+ To be even more performant and cost effective, Shoryuken fetches SQS messages in batches, so a single SQS request can fetch up to 10 messages.
40
40
 
41
41
  ## Requirements
42
42
 
@@ -134,64 +134,11 @@ The ```aws``` section is used to configure both the Aws objects used by Shoryuke
134
134
  - ```sqs_endpoint``` can be used to explicitly override the SQS endpoint
135
135
  - ```receive_message``` can be used to define the options passed to the http://docs.aws.amazon.com/sdkforruby/api/Aws/SQS/Client.html#receive_message-instance_method
136
136
 
137
- ### Rails Integration
138
-
139
- You can tell Shoryuken to load your Rails application by passing the `-R` or `--rails` flag to the "shoryuken" command.
140
-
141
- If you load Rails, and assuming your workers are located in the `app/workers` directory, they will be auto-loaded. This means you don't need to require them explicitly with `-r`.
142
-
143
- For middleware and other configuration, you might want to create an initializer:
144
-
145
- ```ruby
146
- Shoryuken.configure_server do |config|
147
- # Replace Rails logger so messages are logged wherever Shoryuken is logging
148
- # Note: this entire block is only run by the processor, so we don't overwrite
149
- # the logger when the app is running as usual.
150
- Rails.logger = Shoryuken::Logging.logger
151
-
152
- config.server_middleware do |chain|
153
- chain.add Shoryuken::MyMiddleware
154
- end
155
- end
156
- ```
157
-
158
- *Note:* In the above case, since we are replacing the Rails logger, it's desired that this initializer runs before other initializers (in case they themselves use the logger). Since by Rails conventions initializers are executed in alphabetical order, this can be achieved by prepending the initializer filename with `00_` (assuming no other initializers alphabetically precede this one).
159
-
160
- This feature works for Rails 4+, but needs to be confirmed for older versions.
161
-
162
- #### ActiveJob Support
163
-
164
- Yes, Shoryuken supports ActiveJob! This means that you can put your jobs in processor-agnostic `ActiveJob::Base` subclasses, and change processors whenever you want (or better yet, switch to Shoryuken from another processor easily!).
165
-
166
- It works as expected. Just put your job in `app/jobs`. Here's an example:
137
+ The ```sns_endpoint``` and ```sqs_endpoint``` Shoryuken-specific options will also fallback to the environment variables ```AWS_SNS_ENDPOINT``` and ```AWS_SQS_ENDPOINT``` respectively, if they are set.
167
138
 
168
- ```ruby
169
- class ProcessPhotoJob < ActiveJob::Base
170
- queue_as :default
171
-
172
- rescue_from ActiveJob::DeserializationError do |e|
173
- Shoryuken.logger.error ex
174
- Shoryuken.logger.error ex.backtrace.join("\n")
175
- end
176
-
177
- def perform(photo)
178
- photo.process_image!
179
- end
180
- end
181
- ```
182
-
183
- Delayed mailers, ActiveRecord serialization, etc. all work.
184
-
185
- See [ActiveJob docs](http://edgeguides.rubyonrails.org/active_job_basics.html) for more info.
186
-
187
- *Note:* When queueing jobs to be performed in the future (e.g when setting the `wait` or `wait_until` ActiveJob options), SQS limits the amount of time to 15 minutes. Shoryuken will raise an exception if you attempt to schedule a job further into the future than this limit.
188
-
189
- *Note:* Active Job allows you to [prefix the queue names](http://edgeguides.rubyonrails.org/active_job_basics.html#queues) of all jobs. Shoryuken supports this behavior natively. By default, though, queue names defined in the config file (or passed to the CLI), are not prefixed in the same way. To have Shoryuken honor Active Job prefixes you must enable that option explicitly. A good place to do that in Rails is in an initializer:
139
+ ### Rails Integration
190
140
 
191
- ```
192
- # config/initializers/shoryuken.rb
193
- Shoryuken.active_job_queue_name_prefixing = true
194
- ```
141
+ [Check the Rails Integration Active Job documention](https://github.com/phstc/shoryuken/wiki/Rails-Integration-Active-Job).
195
142
 
196
143
  ### Start Shoryuken
197
144
 
@@ -30,7 +30,8 @@ module Shoryuken
30
30
  private
31
31
 
32
32
  def aws_client_options(service_endpoint_key)
33
- explicit_endpoint = Shoryuken.options[:aws][service_endpoint_key]
33
+ environment_endpoint = ENV["AWS_#{service_endpoint_key.to_s.upcase}"]
34
+ explicit_endpoint = Shoryuken.options[:aws][service_endpoint_key] || environment_endpoint
34
35
  options = {}
35
36
  options[:endpoint] = explicit_endpoint unless explicit_endpoint.to_s.empty?
36
37
  options
@@ -1,11 +1,21 @@
1
1
  module Shoryuken
2
2
  class Message
3
- attr_accessor :client, :queue_url, :data
3
+ attr_accessor :client, :queue_url, :queue_name, :data
4
4
 
5
- def initialize(client, queue_url, data)
5
+ def initialize(client, queue, data)
6
6
  self.client = client
7
- self.queue_url = queue_url
8
7
  self.data = data
8
+
9
+ if queue.is_a?(Shoryuken::Queue)
10
+ self.queue_url = queue.url
11
+ self.queue_name = queue.name
12
+ else
13
+ # TODO: Remove next major release
14
+ Shoryuken.loggger.warn do
15
+ '[DEPRECATION] Passing a queue url into Shoryuken::Message is deprecated, please pass the queue itself'
16
+ end
17
+ self.queue_url = queue
18
+ end
9
19
  end
10
20
 
11
21
  def delete
@@ -90,7 +90,7 @@ module Shoryuken
90
90
  end
91
91
  rescue => e
92
92
  logger.error { "Error parsing the message body: #{e.message}\nbody_parser: #{body_parser}\nsqs_msg.body: #{sqs_msg.body}" }
93
- nil
93
+ raise
94
94
  end
95
95
  end
96
96
  end
@@ -34,7 +34,7 @@ module Shoryuken
34
34
  def receive_messages(options)
35
35
  client.receive_message(options.merge(queue_url: url)).
36
36
  messages.
37
- map { |m| Message.new(client, url, m) }
37
+ map { |m| Message.new(client, self, m) }
38
38
  end
39
39
 
40
40
  private
@@ -1,3 +1,3 @@
1
1
  module Shoryuken
2
- VERSION = '1.0.3'
2
+ VERSION = '2.0.0'
3
3
  end
@@ -5,12 +5,13 @@ describe Shoryuken::Client do
5
5
  let(:sqs) { Aws::SQS::Client.new(stub_responses: true, credentials: credentials) }
6
6
  let(:queue_name) { 'shoryuken' }
7
7
  let(:queue_url) { 'https://eu-west-1.amazonaws.com:6059/123456789012/shoryuken' }
8
-
9
- before do
10
- described_class.sqs = sqs
11
- end
8
+ let(:sqs_endpoint) { 'http://localhost:4568' }
9
+ let(:sns_endpoint) { 'http://0.0.0.0:4568' }
12
10
 
13
11
  describe '.queue' do
12
+ before do
13
+ described_class.sqs = sqs
14
+ end
14
15
  it 'memoizes queues' do
15
16
  sqs.stub_responses(:get_queue_url, { queue_url: queue_url }, { queue_url: 'xyz' })
16
17
 
@@ -18,4 +19,44 @@ describe Shoryuken::Client do
18
19
  expect(Shoryuken::Client.queues(queue_name).url).to eq queue_url
19
20
  end
20
21
  end
22
+
23
+ describe 'environment variable endpoints' do
24
+ before do
25
+ ENV['AWS_SQS_ENDPOINT'] = sqs_endpoint
26
+ ENV['AWS_SNS_ENDPOINT'] = sns_endpoint
27
+ ENV['AWS_REGION'] = 'us-east-1'
28
+ Shoryuken.options[:aws] = {}
29
+ end
30
+
31
+ it 'will use config file settings if set' do
32
+ load_config_file_by_file_name('shoryuken_endpoint.yml')
33
+ expect(described_class.sqs.config.endpoint.to_s).to eql('https://github.com/phstc/shoryuken:4568')
34
+ expect(described_class.sns.config.endpoint.to_s).to eq('http://127.0.0.1:4568')
35
+ end
36
+
37
+ it 'should fallback to environment variable if config file not found or set' do
38
+ load_config_file_by_file_name(nil)
39
+ expect(described_class.sqs.config.endpoint.to_s).to eql(sqs_endpoint)
40
+ expect(described_class.sns.config.endpoint.to_s).to eq(sns_endpoint)
41
+ end
42
+
43
+ it 'should fallback to environment variable if config file found but settings not set' do
44
+ load_config_file_by_file_name('shoryuken.yml')
45
+ expect(described_class.sqs.config.endpoint.to_s).to eql(sqs_endpoint)
46
+ expect(described_class.sns.config.endpoint.to_s).to eq(sns_endpoint)
47
+ end
48
+
49
+ it 'will fallback to default settings if no config file settings or environment variables found' do
50
+ ENV['AWS_SQS_ENDPOINT'] = nil
51
+ ENV['AWS_SNS_ENDPOINT'] = nil
52
+ load_config_file_by_file_name('shoryuken.yml')
53
+ expect(described_class.sqs.config.endpoint.to_s).to eql('https://sqs.us-east-1.amazonaws.com')
54
+ expect(described_class.sns.config.endpoint.to_s).to eq('https://sns.us-east-1.amazonaws.com')
55
+ end
56
+ end
57
+
58
+ def load_config_file_by_file_name(file_name)
59
+ path_name = file_name ? File.join(File.expand_path('../../..', __FILE__), 'spec', file_name) : nil
60
+ Shoryuken::EnvironmentLoader.load(config_file: path_name)
61
+ end
21
62
  end
@@ -92,18 +92,22 @@ describe Shoryuken::Processor do
92
92
  end
93
93
 
94
94
  context 'when parse errors' do
95
- it 'does not fail' do
95
+ before do
96
96
  TestWorker.get_shoryuken_options['body_parser'] = :json
97
97
 
98
- expect_any_instance_of(TestWorker).to receive(:perform).with(sqs_msg, nil)
99
-
100
98
  allow(sqs_msg).to receive(:body).and_return('invalid json')
99
+ end
101
100
 
101
+ it 'logs the error' do
102
102
  expect(subject.logger).to receive(:error) do |&block|
103
103
  expect(block.call).to eq("Error parsing the message body: 757: unexpected token at 'invalid json'\nbody_parser: json\nsqs_msg.body: invalid json")
104
104
  end
105
105
 
106
- subject.process(queue, sqs_msg)
106
+ subject.process(queue, sqs_msg) rescue nil
107
+ end
108
+
109
+ it 're raises the error' do
110
+ expect{ subject.process(queue, sqs_msg) }.to raise_error(JSON::ParserError, "757: unexpected token at 'invalid json'")
107
111
  end
108
112
  end
109
113
 
@@ -0,0 +1,6 @@
1
+ aws:
2
+ access_key_id: <%= ENV['AWS_ACCESS_KEY_ID'] %>
3
+ secret_access_key: <%= ENV['AWS_SECRET_ACCESS_KEY'] %>
4
+ region: us-east-1
5
+ sqs_endpoint: https://github.com/phstc/shoryuken:4568
6
+ sns_endpoint: http://127.0.0.1:4568
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shoryuken
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pablo Cantero
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-15 00:00:00.000000000 Z
11
+ date: 2015-09-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -135,6 +135,7 @@ files:
135
135
  - ".rspec"
136
136
  - ".rubocop.yml"
137
137
  - ".travis.yml"
138
+ - CHANGELOG.md
138
139
  - Gemfile
139
140
  - LICENSE.txt
140
141
  - README.md
@@ -186,6 +187,7 @@ files:
186
187
  - spec/shoryuken/topic_spec.rb
187
188
  - spec/shoryuken/util_spec.rb
188
189
  - spec/shoryuken/worker_spec.rb
190
+ - spec/shoryuken_endpoint.yml
189
191
  - spec/shoryuken_spec.rb
190
192
  - spec/spec_helper.rb
191
193
  homepage: https://github.com/phstc/shoryuken
@@ -208,7 +210,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
208
210
  version: '0'
209
211
  requirements: []
210
212
  rubyforge_project:
211
- rubygems_version: 2.2.3
213
+ rubygems_version: 2.2.5
212
214
  signing_key:
213
215
  specification_version: 4
214
216
  summary: Shoryuken is a super efficient AWS SQS thread based message processor
@@ -230,5 +232,6 @@ test_files:
230
232
  - spec/shoryuken/topic_spec.rb
231
233
  - spec/shoryuken/util_spec.rb
232
234
  - spec/shoryuken/worker_spec.rb
235
+ - spec/shoryuken_endpoint.yml
233
236
  - spec/shoryuken_spec.rb
234
237
  - spec/spec_helper.rb