Permalink
Browse files

Merge branch 'feature/sqs-generator'

  • Loading branch information...
2 parents 0b9c728 + 5cf2087 commit 563055040d58cab51bd1559ffaf2ee8a3a01ab00 @marcbowes marcbowes committed Sep 30, 2012
View
@@ -1,44 +1,49 @@
PATH
remote: .
specs:
- daemon-kit (0.1.8.2)
+ daemon-kit (0.2.0)
eventmachine (>= 0.12.10)
+ i18n
+ rubigen
safely (>= 0.3.1)
thor
GEM
remote: http://rubygems.org/
specs:
- SyslogLogger (1.4.0)
- hoe (>= 1.2.0)
- builder (2.1.2)
- cucumber (0.10.2)
+ SyslogLogger (1.4.1)
+ activesupport (3.1.8)
+ multi_json (>= 1.0, < 1.3)
+ builder (3.1.3)
+ cucumber (0.10.7)
builder (>= 2.1.2)
diff-lcs (>= 1.1.2)
- gherkin (>= 2.3.5)
+ gherkin (~> 2.4.0)
json (>= 1.4.6)
term-ansicolor (>= 1.0.5)
- diff-lcs (1.1.2)
- eventmachine (0.12.10)
- gherkin (2.3.5)
+ diff-lcs (1.1.3)
+ eventmachine (1.0.0)
+ gherkin (2.4.21)
json (>= 1.4.6)
- hoe (2.9.4)
- rake (>= 0.8.7)
- json (1.5.1)
+ i18n (0.6.1)
+ json (1.7.5)
mocha (0.9.12)
- rake (0.8.7)
- rdoc (3.11)
+ multi_json (1.2.0)
+ rake (0.9.2.2)
+ rdoc (3.12)
json (~> 1.4)
- rspec (2.6.0)
- rspec-core (~> 2.6.0)
- rspec-expectations (~> 2.6.0)
- rspec-mocks (~> 2.6.0)
- rspec-core (2.6.3)
- rspec-expectations (2.6.0)
- diff-lcs (~> 1.1.2)
- rspec-mocks (2.6.0)
- safely (0.3.1)
- term-ansicolor (1.0.5)
+ rspec (2.11.0)
+ rspec-core (~> 2.11.0)
+ rspec-expectations (~> 2.11.0)
+ rspec-mocks (~> 2.11.0)
+ rspec-core (2.11.1)
+ rspec-expectations (2.11.3)
+ diff-lcs (~> 1.1.3)
+ rspec-mocks (2.11.3)
+ rubigen (1.5.8)
+ activesupport (>= 2.3.5, < 3.2.0)
+ safely (0.3.2)
+ term-ansicolor (1.0.7)
thor (0.16.0)
PLATFORMS
View
@@ -1,10 +1,17 @@
-== 0.1.9 (WIP)
+== 0.2.0 2012-09-30
* Depend on the 'safely' gem for the safely method and logging backtraces
* Fixed compatibility with ruote-amqp 2.2.0
-* AMQP fixes by @marcbowes
+* AMQP fixes by @marcbowes (version, reconnect)
* Updated to rspec 2 (various contributors)
-* Up to AMQP gem 0.7.1 or later
+* Various documentation fixes by @ktrix
+* Remove vendored Thor
+* Various load/require fixes by @ktrix
+* SQS generator by @marcbowes
+
+== 0.1.8.2 2011-05-18
+
+* Convert to use Bundler
== 0.1.18.1 2010-08-04
View
@@ -15,6 +15,7 @@ Supported generators:
* XMPP bot (evented)
* AMQP consumer (evented)
+* SQS consumer
* Nanite agent
* Cron-style daemon
* ruote remote participants
View
@@ -44,4 +44,6 @@ $ daemon-kit -h
gem.add_development_dependency(%q<SyslogLogger>)
gem.add_runtime_dependency(%q<eventmachine>, [">= 0.12.10"])
gem.add_runtime_dependency(%q<safely>, [">= 0.3.1"])
+ gem.add_runtime_dependency(%q<rubigen>)
+ gem.add_runtime_dependency(%q<i18n>)
end
View
@@ -29,6 +29,7 @@ module DaemonKit
autoload :Cron, 'daemon_kit/cron'
autoload :Jabber, 'daemon_kit/jabber'
autoload :AMQP, 'daemon_kit/dk_amqp'
+ autoload :SQS, 'daemon_kit/dk_sqs'
autoload :Nanite, 'daemon_kit/nanite'
autoload :RuoteParticipants, 'daemon_kit/ruote_participants'
autoload :RuoteWorkitem, 'daemon_kit/ruote_workitem'
View
@@ -16,6 +16,8 @@ module DaemonKit
# Any of the keys can be called as methods as well.
class Config
+ require "yaml"
+
class << self
# Load the +config+.yml file from DAEMON_ROOT/config
View
@@ -0,0 +1,35 @@
+require "aws/sqs"
+
+module DaemonKit
+ # Thin wrapper around the aws-sdk gem, specifically designed to ease
+ # configuration of the SQS client
+ class SQS
+
+ @@instance = nil
+
+ class << self
+
+ def instance
+ @instance ||= new
+ end
+
+ private :new
+
+ def run(config = {}, &block)
+ instance.run(config, &block)
+ end
+ end
+
+ def initialize
+ @config = DaemonKit::Config.load("sqs").to_h(true)
+ end
+
+ def run(config = {}, &block)
+ sqs_config = @config.merge(config)
+ DaemonKit.logger.debug("AWS::SQS.new(#{sqs_config.inspect})")
+ sqs = ::AWS::SQS.new(sqs_config)
+ DaemonKit.logger.debug("# => #{sqs.client.inspect}")
+ block.call(sqs)
+ end
+ end
+end
@@ -5,6 +5,7 @@ module Generators
autoload :AppGenerator, 'generators/daemon_kit/app/app_generator'
autoload :CucumberGenerator, 'generators/daemon_kit/cucumber/cucumber_generator'
autoload :AmqpGenerator, 'generators/daemon_kit/amqp/amqp_generator'
+ autoload :SqsGenerator, 'generators/daemon_kit/sqs/sqs_generator'
autoload :CronGenerator, 'generators/daemon_kit/cron/cron_generator'
autoload :CapistranoGenerator, 'generators/daemon_kit/capistrano/capistrano_generator'
autoload :NaniteAgentGenerator, 'generators/daemon_kit/nanite_agent/nanite_agent_generator'
@@ -1,6 +1,6 @@
module DaemonKit
def version
- '0.1.8.2'
+ '0.2.0'
end
module_function :version
end
@@ -1,7 +1,7 @@
module DaemonKit
module Generators
class AppGenerator < Base
- INSTALLERS = %w( default amqp cron nanite_agent ruote xmpp )
+ INSTALLERS = %w( default amqp sqs cron nanite_agent ruote xmpp )
DEPLOYERS = %w( capistrano )
TEST_FRAMEWORKS = %w( none rspec test_unit )
add_shebang_option!
@@ -93,6 +93,8 @@ def create_lib_exec
directory 'libexec'
when 'amqp'
invoke DaemonKit::Generators::AmqpGenerator
+ when 'sqs'
+ invoke DaemonKit::Generators::SqsGenerator
when 'cron'
invoke DaemonKit::Generators::CronGenerator
when 'nanite_agent'
@@ -0,0 +1,5 @@
+Description:
+
+
+Usage:
+
@@ -0,0 +1,24 @@
+module DaemonKit
+ module Generators
+ class SqsGenerator < Base
+
+ def update_gemfile
+ append_file 'Gemfile', "gem 'aws-sdk'\n"
+ end
+
+ def create_config_files
+ directory 'config'
+ end
+
+ def create_daemon
+ directory 'libexec'
+ end
+
+ protected
+
+ def self.source_root
+ File.expand_path( File.join( File.dirname(__FILE__), 'templates') )
+ end
+ end
+ end
+end
@@ -0,0 +1,6 @@
+begin
+ require 'aws-sdk'
+rescue LoadError
+ $stderr.puts "Missing aws-sdk gem. Please run 'bundle install'."
+ exit 1
+end
@@ -0,0 +1,20 @@
+# SQS client configuration file
+
+# Variables in this file are passed directly into AWS::SQS.new.
+# Please refer to the aws-sdk configuration for the most up-to-date
+# list of options. If your credentials are available as environment
+# variables or you're on an EC2 instance configured with an IAM role,
+# you can simply delete the access/secret keys.
+
+defaults: &defaults
+ access_key_id: your-access-key
+ secret_access_key: your-secret-key
+
+development:
+ <<: *defaults
+
+test:
+ <<: *defaults
+
+production:
+ <<: *defaults
@@ -0,0 +1,39 @@
+# Generated sqs daemon
+
+# Do your post daemonization configuration here
+# At minimum you need just the first line (without the block), or a lot
+# of strange things might start happening...
+DaemonKit::Application.running! do |config|
+ # Trap signals with blocks or procs
+ # config.trap( 'INT' ) do
+ # # do something clever
+ # end
+ # config.trap( 'TERM', Proc.new { puts 'Going down' } )
+end
+
+# IMPORTANT CONFIGURATION NOTES
+#
+# The aws-sdk gem provides various mechanisms for configuring the
+# client libraries. It is recommended that you look at the
+# documentation for the most up-to-date or appropriate way of
+# configuring it.
+#
+# At the time of writing, the (aws-sdk) gem will attempt to use
+# environment variables or the EC2 metadata service to auto-configure
+# itself. If this is not the case, you can pass configuration options
+# into DaemonKit::SQS.run which will be passed on to the underlying
+# AWS::SQS client. By default, we use the 'config/sqs.yml' file to do
+# this configuration.
+
+# Run an event-loop for processing
+DaemonKit::SQS.run do |sqs|
+ # Inside this block you have access to an AWS::SQS
+
+ queue = sqs.queues[sqs.queues.url_for('test')]
+ queue.poll do |msg|
+ # msg may be nil if long-polling is disabled or the poll expires -
+ # in either case, this is an indication that the queue is (almost)
+ # empty
+ DaemonKit.logger.debug "Received message: #{msg.inspect}"
+ end
+end
View
@@ -0,0 +1,48 @@
+require File.join(File.dirname(__FILE__), "test_generator_helper.rb")
+
+
+class TestSqsGenerator < Test::Unit::TestCase
+ include RubiGen::GeneratorTestHelper
+
+ def setup
+ bare_setup
+ end
+
+ def teardown
+ bare_teardown
+ end
+
+ # Some generator-related assertions:
+ # assert_generated_file(name, &block) # block passed the file contents
+ # assert_directory_exists(name)
+ # assert_generated_class(name, &block)
+ # assert_generated_module(name, &block)
+ # assert_generated_test_for(name, &block)
+ # The assert_generated_(class|module|test_for) &block is passed the body of the class/module within the file
+ # assert_has_method(body, *methods) # check that the body has a list of methods (methods with parentheses not supported yet)
+ #
+ # Other helper methods are:
+ # app_root_files - put this in teardown to show files generated by the test method (e.g. p app_root_files)
+ # bare_setup - place this in setup method to create the APP_ROOT folder for each test
+ # bare_teardown - place this in teardown method to destroy the TMP_ROOT or APP_ROOT folder after each test
+
+ def test_generator_without_options
+ name = "myapp"
+ run_generator('sqs', [name], sources)
+ assert_directory_exists "config"
+ assert_directory_exists "config/initializers"
+ assert_generated_file "config/sqs.yml"
+ assert_generated_file "config/initializers/myapp.rb"
+ assert_generated_file "libexec/myapp-daemon.rb"
+ end
+
+ private
+ def sources
+ [RubiGen::PathSource.new(:test, File.join(File.dirname(__FILE__),"..", generator_path))
+ ]
+ end
+
+ def generator_path
+ "daemon_generators"
+ end
+end

0 comments on commit 5630550

Please sign in to comment.