Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

more flexibility in the config file and right_aws not required #2

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/workling.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@ def self.config

return nil unless File.exists?(config_path)

yaml_config= YAML.load(ERB.new(IO.read(config_path)).result)
config_name = (yaml_config[env] ? env : (yaml_config['development'] ? 'development' : 'default'))
config=yaml_config[config_name]
raise "Can't find a configuration for the environments #{env}, development or default" unless config

@@config ||= YAML.load_file(config_path)[env || 'development'].symbolize_keys
@@config[:memcache_options].symbolize_keys! if @@config[:memcache_options]
@@config
Expand Down
19 changes: 17 additions & 2 deletions lib/workling/clients/sqs_client.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require 'json'
require 'right_aws'

#
# An SQS client
Expand Down Expand Up @@ -37,7 +36,23 @@ class SqsClient < Workling::Clients::BrokerBase
DEFAULT_VISIBILITY_TIMEOUT = 30
DEFAULT_VISIBILITY_RESERVE = 10
end


def self.load
raise WorklingError.new(
"WORKLING: couldn't find the ruby aws client - you need it for the sqs runner. " \
"Install it with sudo gem install right_aws "
) unless installed?
end

def self.installed?
begin
gem 'right_aws'
require 'right_aws'
rescue LoadError
end

Object.const_defined? "RightAws"
end
# Mainly exposed for testing purposes
attr_reader :sqs_options
attr_reader :messages_per_req
Expand Down
17 changes: 17 additions & 0 deletions test/extensions/clients/sqs_client_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require File.dirname(__FILE__) + '/../../test_helper'
require 'right_aws'

context "The SQS client" do

Expand All @@ -19,6 +20,22 @@
@client.stubs(:env).returns('test')
@client.connect
end

context "loading" do

specify "should be installed" do
Workling::Clients::SqsClient.installed?.should == true
end

specify "should be able to load" do
lambda { Workling::Clients::SqsClient.load}.should.not.raise
end

specify "should raise on load if not installed" do
Workling::Clients::SqsClient.stubs(:installed?).returns(false)
lambda { Workling::Clients::SqsClient.load}.should.raise Workling::WorklingError
end
end

context "when connecting" do

Expand Down