diff --git a/lib/workling.rb b/lib/workling.rb index 7640642..bdc9093 100644 --- a/lib/workling.rb +++ b/lib/workling.rb @@ -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 diff --git a/lib/workling/clients/sqs_client.rb b/lib/workling/clients/sqs_client.rb index 68ac70e..d7c3201 100644 --- a/lib/workling/clients/sqs_client.rb +++ b/lib/workling/clients/sqs_client.rb @@ -1,5 +1,4 @@ require 'json' -require 'right_aws' # # An SQS client @@ -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 diff --git a/test/extensions/clients/sqs_client_test.rb b/test/extensions/clients/sqs_client_test.rb index c97b144..33f13a9 100644 --- a/test/extensions/clients/sqs_client_test.rb +++ b/test/extensions/clients/sqs_client_test.rb @@ -1,4 +1,5 @@ require File.dirname(__FILE__) + '/../../test_helper' +require 'right_aws' context "The SQS client" do @@ -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