Skip to content

Commit

Permalink
Merge branch 'master' of github.com:phstc/shoryuken into strict_prior…
Browse files Browse the repository at this point in the history
…ity_polling

# Conflicts:
#	lib/shoryuken/fetcher.rb
#	lib/shoryuken/manager.rb
#	lib/shoryuken/polling.rb
#	spec/shoryuken/polling_spec.rb
  • Loading branch information
atyndall committed Dec 13, 2016
2 parents a922c95 + e83a68b commit 1eab6b6
Show file tree
Hide file tree
Showing 25 changed files with 377 additions and 222 deletions.
23 changes: 23 additions & 0 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
engines:
brakeman:
enabled: true
bundler-audit:
enabled: true
duplication:
enabled: true
config:
languages:
- ruby
fixme:
enabled: true
reek:
enabled: true
rubocop:
enabled: true
ratings:
paths:
- "**.rb"
# exclude_paths:
# - "**/vendor/**/*"
# - "*/spec/**/*"
6 changes: 0 additions & 6 deletions .hound.yml

This file was deleted.

7 changes: 2 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
language: ruby
rvm:
# - 1.9.3
# - 1.9.2
- 2.0.0
- 2.1.0
- 2.2.0
# - ruby-head
# - jruby-19mode
# - jruby-head

notifications:
email:
Expand All @@ -17,3 +12,5 @@ notifications:
script: SPEC_ALL=true bundle exec rspec spec
before_install:
- gem update bundler
after_success:
- bundle exec codeclimate-test-reporter
51 changes: 40 additions & 11 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,45 +1,74 @@
## [v2.1.1] - 2016-12-05
- Fix aws deprecation warning message
- [#279](https://github.com/phstc/shoryuken/pull/279)

## [v2.1.0] - 2016-12-03
- Fix celluloid "running in BACKPORTED mode" warning
- [#260](https://github.com/phstc/shoryuken/pull/260)

- Allow setting the aws configuration in 'Shoryuken.configure_server'
- [#252](https://github.com/phstc/shoryuken/pull/252)

- Allow requiring a file or dir a through `-r`
- [#248](https://github.com/phstc/shoryuken/pull/248)

- Reduce info log verbosity
- [#243](https://github.com/phstc/shoryuken/pull/243)

- Fix auto extender when using ActiveJob
- [#3213](https://github.com/phstc/shoryuken/pull/213)

- Add FIFO queue support
- [#272](https://github.com/phstc/shoryuken/issues/272)

- Deprecates initialize_aws
- [#269](https://github.com/phstc/shoryuken/pull/269)

- [Other miscellaneous updates](https://github.com/phstc/shoryuken/compare/v2.0.11...v2.1.0)

## [v2.0.11] - 2016-07-02

- Same as 2.0.10. Unfortunately 2.0.10 was removed `yanked` by mistake from RubyGems.
- [#b255bc3] https://github.com/phstc/shoryuken/commit/b255bc3
- [#b255bc3](https://github.com/phstc/shoryuken/commit/b255bc3)

## [v2.0.10] - 2016-06-09

- Fix manager #225
- [#226] https://github.com/phstc/shoryuken/pull/226
- [#226](https://github.com/phstc/shoryuken/pull/226)

## [v2.0.9] - 2016-06-08

- Fix daemonization broken in #219
- [#224] https://github.com/phstc/shoryuken/pull/224
- [#224](https://github.com/phstc/shoryuken/pull/224)

## [v2.0.8] - 2016-06-07

- Fix daemonization
- [#223] https://github.com/phstc/shoryuken/pull/223
- [#223](https://github.com/phstc/shoryuken/pull/223)

## [v2.0.7] - 2016-06-06

- Daemonize before loading environment
- [#219] https://github.com/phstc/shoryuken/pull/219
- [#219](https://github.com/phstc/shoryuken/pull/219)

- Fix initialization when using rails
- [#197] https://github.com/phstc/shoryuken/pull/197
- [#197](https://github.com/phstc/shoryuken/pull/197)

- Improve message fetching
- https://github.com/phstc/shoryuken/pull/214 and https://github.com/phstc/shoryuken/commit/f4640d97950c1783a061195855d93994725ed64a
- [#214](https://github.com/phstc/shoryuken/pull/214)
- [#f4640d9](https://github.com/phstc/shoryuken/commit/f4640d9)

- Fix hard shutdown if there are some busy workers when signal received
- [#215] https://github.com/phstc/shoryuken/pull/215
- [#215](https://github.com/phstc/shoryuken/pull/215)

- Fix `rake console` task
- [#208] https://github.com/phstc/shoryuken/pull/208
- [#208](https://github.com/phstc/shoryuken/pull/208)

- Isolate `MessageVisibilityExtender` as new middleware
- [#199] https://github.com/phstc/shoryuken/pull/190
- [#199](https://github.com/phstc/shoryuken/pull/190)

- Fail on non-existent queues
- [#196] https://github.com/phstc/shoryuken/pull/196
- [#196](https://github.com/phstc/shoryuken/pull/196)

## [v2.0.6] - 2016-04-18

Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ gemspec

group :test do
gem 'codeclimate-test-reporter', require: nil
gem 'simplecov'
gem 'multi_xml'
end
File renamed without changes.
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ end
desc 'Open Shoryuken pry console'
task :console do
require 'pry'
require 'celluloid'
require 'celluloid/current'
require 'shoryuken'

config_file = File.join File.expand_path('..', __FILE__), 'shoryuken.yml'
Expand Down
13 changes: 1 addition & 12 deletions examples/default_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,6 @@ class DefaultWorker
shoryuken_options queue: 'default', auto_delete: true

def perform(sqs_msg, body)
puts "DefaultWorker: '#{body}'"
end
end

# multiple workers for the same queue
class DefaultWorker2
include Shoryuken::Worker

shoryuken_options queue: 'default', auto_delete: true

def perform(sqs_msg, body)
puts "DefaultWorker2: '#{body}'"
Shoryuken.logger.info("Received message: '#{body}'")
end
end
19 changes: 18 additions & 1 deletion lib/shoryuken.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
require 'shoryuken/core_ext'
require 'shoryuken/util'
require 'shoryuken/logging'
require 'shoryuken/aws_config'
require 'shoryuken/environment_loader'
require 'shoryuken/queue'
require 'shoryuken/message'
Expand Down Expand Up @@ -74,6 +75,12 @@ def active_job_queue_name_prefixing=(prefixing)
@@active_job_queue_name_prefixing = prefixing
end

##
# Configuration for Shoryuken server, use like:
#
# Shoryuken.configure_server do |config|
# config.aws = { :sqs_endpoint => '...', :access_key_id: '...', :secret_access_key: '...', region: '...' }
# end
def configure_server
yield self if server?
end
Expand All @@ -84,8 +91,14 @@ def server_middleware
@server_chain
end

##
# Configuration for Shoryuken client, use like:
#
# Shoryuken.configure_client do |config|
# config.aws = { :sqs_endpoint => '...', :access_key_id: '...', :secret_access_key: '...', region: '...' }
# end
def configure_client
yield self
yield self unless server?
end

def client_middleware
Expand Down Expand Up @@ -120,6 +133,10 @@ def on_stop(&block)
@stop_callback = block
end

def aws=(hash)
Shoryuken::AwsConfig.setup(hash)
end

# Register a block to run at a point in the Shoryuken lifecycle.
# :startup, :quiet or :shutdown are valid events.
#
Expand Down
64 changes: 64 additions & 0 deletions lib/shoryuken/aws_config.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# frozen_string_literal: true
module Shoryuken
class AwsConfig
class << self
attr_writer :options

def options
@options ||= {}
end

def setup(hash)
# aws-sdk tries to load the credentials from the ENV variables: AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY
# when not explicit supplied
return if hash.empty?

self.options = hash

shoryuken_keys = %w(
account_id
sns_endpoint
sqs_endpoint
receive_message
).map(&:to_sym)

@aws_options = hash.reject do |k, _|
shoryuken_keys.include?(k)
end

# assume credentials based authentication
credentials = Aws::Credentials.new(
@aws_options.delete(:access_key_id),
@aws_options.delete(:secret_access_key)
)

# but only if the configuration options have valid values
@aws_options.merge!(credentials: credentials) if credentials.set?

if (callback = Shoryuken.aws_initialization_callback)
Shoryuken.logger.info { 'Calling Shoryuken.on_aws_initialization block' }
callback.call(@aws_options)
end
end

def sns
Aws::SNS::Client.new(aws_client_options(:sns_endpoint))
end

def sqs
Aws::SQS::Client.new(aws_client_options(:sqs_endpoint))
end

private

def aws_client_options(service_endpoint_key)
environment_endpoint = ENV["AWS_#{service_endpoint_key.to_s.upcase}"]
explicit_endpoint = options[service_endpoint_key] || environment_endpoint
endpoint = {}.tap do |hash|
hash[:endpoint] = explicit_endpoint unless explicit_endpoint.to_s.empty?
end
@aws_options.to_h.merge(endpoint)
end
end
end
end
13 changes: 9 additions & 4 deletions lib/shoryuken/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,15 @@ def run(args)

options = parse_cli_args(args)

daemonize(options)
write_pid(options)
loader = EnvironmentLoader.setup_options(options)

EnvironmentLoader.load(options)
# When cli args exist, override options in config file
Shoryuken.options.merge!(options)

daemonize(Shoryuken.options)
write_pid(Shoryuken.options)

loader.load

load_celluloid

Expand Down Expand Up @@ -64,7 +69,7 @@ def run(args)
private

def load_celluloid
require 'celluloid/autostart'
require 'celluloid/current'
Celluloid.logger = (Shoryuken.options[:verbose] ? Shoryuken.logger : nil)

require 'shoryuken/manager'
Expand Down
14 changes: 2 additions & 12 deletions lib/shoryuken/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ def queues(name)
end

def sns
@sns ||= Aws::SNS::Client.new(aws_client_options(:sns_endpoint))
@sns ||= Shoryuken::AwsConfig.sns
end

def sns_arn
@sns_arn ||= SnsArn
end

def sqs
@sqs ||= Aws::SQS::Client.new(aws_client_options(:sqs_endpoint))
@sqs ||= Shoryuken::AwsConfig.sqs
end

def topics(name)
Expand All @@ -26,16 +26,6 @@ def topics(name)

attr_accessor :account_id
attr_writer :sns, :sqs, :sqs_resource, :sns_arn

private

def aws_client_options(service_endpoint_key)
environment_endpoint = ENV["AWS_#{service_endpoint_key.to_s.upcase}"]
explicit_endpoint = Shoryuken.options[:aws][service_endpoint_key] || environment_endpoint
options = {}
options[:endpoint] = explicit_endpoint unless explicit_endpoint.to_s.empty?
options
end
end
end
end
Loading

0 comments on commit 1eab6b6

Please sign in to comment.