daemon-kit 0.1.8.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. data/History.txt +10 -3
  2. data/README.rdoc +1 -0
  3. data/daemon-kit.gemspec +6 -2
  4. data/lib/daemon_kit.rb +1 -0
  5. data/lib/daemon_kit/application.rb +3 -3
  6. data/lib/daemon_kit/arguments.rb +18 -8
  7. data/lib/daemon_kit/config.rb +2 -0
  8. data/lib/daemon_kit/dk_sqs.rb +35 -0
  9. data/lib/daemon_kit/generators.rb +1 -3
  10. data/lib/daemon_kit/initializer.rb +10 -3
  11. data/lib/daemon_kit/version.rb +1 -1
  12. data/lib/generators/daemon_kit/amqp/templates/libexec/%app_name%-daemon.rb +3 -5
  13. data/lib/generators/daemon_kit/app/app_generator.rb +3 -1
  14. data/lib/generators/daemon_kit/app/templates/Gemfile +2 -2
  15. data/lib/generators/daemon_kit/app/templates/README.tt +7 -0
  16. data/lib/generators/daemon_kit/app/templates/config/environment.rb.tt +1 -1
  17. data/lib/generators/daemon_kit/rspec/rspec_generator.rb +10 -0
  18. data/lib/generators/daemon_kit/rspec/templates/spec/spec_helper.rb +3 -4
  19. data/lib/generators/daemon_kit/rspec/templates/tasks/rspec.rake +9 -17
  20. data/lib/generators/daemon_kit/sqs/USAGE +5 -0
  21. data/lib/generators/daemon_kit/sqs/sqs_generator.rb +24 -0
  22. data/lib/generators/daemon_kit/sqs/templates/config/pre-daemonize/sqs.rb +6 -0
  23. data/lib/generators/daemon_kit/sqs/templates/config/sqs.yml +20 -0
  24. data/lib/generators/daemon_kit/sqs/templates/libexec/%app_name%-daemon.rb +39 -0
  25. data/spec/daemon_kit_spec.rb +3 -1
  26. data/spec/initializer_spec.rb +4 -0
  27. data/tasks/rspec.rake +5 -17
  28. data/test/test_sqs_generator.rb +48 -0
  29. metadata +148 -181
  30. data/PostInstall.txt +0 -6
  31. data/lib/daemon_kit/vendor/thor-0.13.6/CHANGELOG.rdoc +0 -89
  32. data/lib/daemon_kit/vendor/thor-0.13.6/LICENSE +0 -20
  33. data/lib/daemon_kit/vendor/thor-0.13.6/README.rdoc +0 -297
  34. data/lib/daemon_kit/vendor/thor-0.13.6/Thorfile +0 -69
  35. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor.rb +0 -244
  36. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/actions.rb +0 -296
  37. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/actions/create_file.rb +0 -103
  38. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/actions/directory.rb +0 -91
  39. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/actions/empty_directory.rb +0 -134
  40. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/actions/file_manipulation.rb +0 -223
  41. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/actions/inject_into_file.rb +0 -104
  42. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/base.rb +0 -540
  43. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/core_ext/file_binary_read.rb +0 -9
  44. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/core_ext/hash_with_indifferent_access.rb +0 -75
  45. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/core_ext/ordered_hash.rb +0 -100
  46. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/error.rb +0 -30
  47. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/group.rb +0 -271
  48. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/invocation.rb +0 -180
  49. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/parser.rb +0 -4
  50. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/parser/argument.rb +0 -67
  51. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/parser/arguments.rb +0 -150
  52. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/parser/option.rb +0 -128
  53. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/parser/options.rb +0 -169
  54. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/rake_compat.rb +0 -66
  55. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/runner.rb +0 -314
  56. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/shell.rb +0 -83
  57. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/shell/basic.rb +0 -239
  58. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/shell/color.rb +0 -108
  59. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/task.rb +0 -102
  60. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/util.rb +0 -224
  61. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/version.rb +0 -3
data/History.txt CHANGED
@@ -1,10 +1,17 @@
1
- == 0.1.9 (WIP)
1
+ == 0.2.0 2012-09-30
2
2
 
3
3
  * Depend on the 'safely' gem for the safely method and logging backtraces
4
4
  * Fixed compatibility with ruote-amqp 2.2.0
5
- * AMQP fixes by @marcbowes
5
+ * AMQP fixes by @marcbowes (version, reconnect)
6
6
  * Updated to rspec 2 (various contributors)
7
- * Up to AMQP gem 0.7.1 or later
7
+ * Various documentation fixes by @ktrix
8
+ * Remove vendored Thor
9
+ * Various load/require fixes by @ktrix
10
+ * SQS generator by @marcbowes
11
+
12
+ == 0.1.8.2 2011-05-18
13
+
14
+ * Convert to use Bundler
8
15
 
9
16
  == 0.1.18.1 2010-08-04
10
17
 
data/README.rdoc CHANGED
@@ -15,6 +15,7 @@ Supported generators:
15
15
 
16
16
  * XMPP bot (evented)
17
17
  * AMQP consumer (evented)
18
+ * SQS consumer
18
19
  * Nanite agent
19
20
  * Cron-style daemon
20
21
  * ruote remote participants
data/daemon-kit.gemspec CHANGED
@@ -10,7 +10,9 @@ Gem::Specification.new do |gem|
10
10
  gem.post_install_message = %q{
11
11
  For more information on daemon-kit, see http://kit.rubyforge.org/daemon-kit
12
12
 
13
- To get started quickly run 'daemon-kit' without any arguments
13
+ For usage options, run:
14
+
15
+ $ daemon-kit -h
14
16
 
15
17
 
16
18
  }
@@ -27,12 +29,12 @@ To get started quickly run 'daemon-kit' without any arguments
27
29
  "Deployment.txt",
28
30
  "History.txt",
29
31
  "Logging.txt",
30
- "PostInstall.txt",
31
32
  "README.rdoc",
32
33
  "RuoteParticipants.txt",
33
34
  "TODO.txt",
34
35
  ]
35
36
 
37
+ gem.add_dependency(%q<thor>)
36
38
  gem.add_development_dependency(%q<bundler>)
37
39
  gem.add_development_dependency(%q<rake>)
38
40
  gem.add_development_dependency(%q<rdoc>)
@@ -42,4 +44,6 @@ To get started quickly run 'daemon-kit' without any arguments
42
44
  gem.add_development_dependency(%q<SyslogLogger>)
43
45
  gem.add_runtime_dependency(%q<eventmachine>, [">= 0.12.10"])
44
46
  gem.add_runtime_dependency(%q<safely>, [">= 0.3.1"])
47
+ gem.add_runtime_dependency(%q<rubigen>)
48
+ gem.add_runtime_dependency(%q<i18n>)
45
49
  end
data/lib/daemon_kit.rb CHANGED
@@ -29,6 +29,7 @@ module DaemonKit
29
29
  autoload :Cron, 'daemon_kit/cron'
30
30
  autoload :Jabber, 'daemon_kit/jabber'
31
31
  autoload :AMQP, 'daemon_kit/dk_amqp'
32
+ autoload :SQS, 'daemon_kit/dk_sqs'
32
33
  autoload :Nanite, 'daemon_kit/nanite'
33
34
  autoload :RuoteParticipants, 'daemon_kit/ruote_participants'
34
35
  autoload :RuoteWorkitem, 'daemon_kit/ruote_workitem'
@@ -32,7 +32,7 @@ module DaemonKit
32
32
  self.chroot
33
33
  self.clean_fd
34
34
  self.redirect_io( true )
35
-
35
+
36
36
  DaemonKit.configuration.log_stdout = true
37
37
 
38
38
  require file
@@ -50,7 +50,7 @@ module DaemonKit
50
50
  end
51
51
 
52
52
  def stop
53
- @pid_file = PidFile.new( DaemonKit.configuration.pid_file )
53
+ @pid_file = PidFile.new( DaemonKit.configuration.pid_file( DaemonKit.configuration.instance ) )
54
54
 
55
55
  unless @pid_file.running?
56
56
  @pid_file.cleanup
@@ -153,7 +153,7 @@ module DaemonKit
153
153
 
154
154
  # Daemonize the process
155
155
  def daemonize
156
- @pid_file = PidFile.new( DaemonKit.configuration.pid_file )
156
+ @pid_file = PidFile.new( DaemonKit.configuration.pid_file( DaemonKit.configuration.instance ) )
157
157
  @pid_file.ensure_stopped!
158
158
 
159
159
  if RUBY_VERSION < "1.9"
@@ -65,13 +65,13 @@ module DaemonKit
65
65
 
66
66
  i = 0
67
67
  while i < argv.size
68
- if argv[i] == "--config"
68
+ if argv[i] == "-c" || argv[i] == "--config"
69
69
  argv.delete_at( i )
70
70
  configs << argv.delete_at(i)
71
71
  next
72
72
  end
73
73
 
74
- if argv[i] == "-e" || argv[i] == "--env"
74
+ if argv[i] == "-e" || argv[i] == "--env" || argv[i] == "--environment"
75
75
  argv.delete_at( i )
76
76
  configs << "environment=#{argv.delete_at(i)}"
77
77
  next
@@ -83,7 +83,13 @@ module DaemonKit
83
83
  next
84
84
  end
85
85
 
86
- if argv[i] == "--pidfile" || argv[i] == "--pid"
86
+ if argv[i] == "-i" || argv[i] == "--instance"
87
+ argv.delete_at( i )
88
+ configs << "instance=#{argv.delete_at(i)}"
89
+ next
90
+ end
91
+
92
+ if argv[i] == "-p" || argv[i] == "--pidfile" || argv[i] == "--pid"
87
93
  argv.delete_at( i )
88
94
  configs << "pid_file=#{argv.delete_at(i)}"
89
95
  next
@@ -123,23 +129,27 @@ module DaemonKit
123
129
  arg_file = File.join( DaemonKit.root, 'config', 'arguments.rb' )
124
130
  eval(IO.read(arg_file), binding, arg_file) if File.exists?( arg_file )
125
131
 
126
- opts.on("-e", "--env ENVIRONMENT", "Environment for the process", "Defaults to development") do
132
+ opts.on("-e", "--env", "--environment ENV", "Environment for the process", " Default: development") do
133
+ # Nothing, just here for show
134
+ end
135
+
136
+ opts.on("-i", "--instance N", "Process instance number", " Default: 1") do
127
137
  # Nothing, just here for show
128
138
  end
129
139
 
130
- opts.on("--pidfile PATH", "Path to the pidfile", "Defaults to log/#{DaemonKit.configuration.daemon_name}.pid") do
140
+ opts.on("-p", "--pid", "--pidfile PATH", "Path to the pidfile", " Default: log/#{DaemonKit.configuration.daemon_name}.N.pid") do
131
141
  # Nothing, just here for show
132
142
  end
133
143
 
134
- opts.on("-l", "--log /path/to/logfile", "Path to the log file", "Defaults to log/[environment].log") do
144
+ opts.on("-l", "--log PATH", "Path to the log file", " Default: log/[environment].log") do
135
145
  # Nothing, just here for show
136
146
  end
137
147
 
138
148
  opts.separator ""
139
149
  opts.separator "Advanced configurations:"
140
- opts.on("--config ATTRIBUTE=VALUE",
150
+ opts.on("-c", "--config ATTRIBUTE=VALUE",
141
151
  "Change values of the daemon-kit Configuration instance",
142
- "Example: log_dir=/path/to/log-directory") do
152
+ " Example: log_dir=/path/to/log-directory") do
143
153
  # Nothing, just here for show
144
154
  end
145
155
 
@@ -16,6 +16,8 @@ module DaemonKit
16
16
  # Any of the keys can be called as methods as well.
17
17
  class Config
18
18
 
19
+ require "yaml"
20
+
19
21
  class << self
20
22
 
21
23
  # Load the +config+.yml file from DAEMON_ROOT/config
@@ -0,0 +1,35 @@
1
+ require "aws/sqs"
2
+
3
+ module DaemonKit
4
+ # Thin wrapper around the aws-sdk gem, specifically designed to ease
5
+ # configuration of the SQS client
6
+ class SQS
7
+
8
+ @@instance = nil
9
+
10
+ class << self
11
+
12
+ def instance
13
+ @instance ||= new
14
+ end
15
+
16
+ private :new
17
+
18
+ def run(config = {}, &block)
19
+ instance.run(config, &block)
20
+ end
21
+ end
22
+
23
+ def initialize
24
+ @config = DaemonKit::Config.load("sqs").to_h(true)
25
+ end
26
+
27
+ def run(config = {}, &block)
28
+ sqs_config = @config.merge(config)
29
+ DaemonKit.logger.debug("AWS::SQS.new(#{sqs_config.inspect})")
30
+ sqs = ::AWS::SQS.new(sqs_config)
31
+ DaemonKit.logger.debug("# => #{sqs.client.inspect}")
32
+ block.call(sqs)
33
+ end
34
+ end
35
+ end
@@ -1,6 +1,3 @@
1
- # TODO: Don't always depend on bundled thor
2
- $:.unshift File.dirname(__FILE__) + '/vendor/thor-0.13.6/lib'
3
-
4
1
  require 'daemon_kit/generators/base'
5
2
 
6
3
  module DaemonKit
@@ -8,6 +5,7 @@ module DaemonKit
8
5
  autoload :AppGenerator, 'generators/daemon_kit/app/app_generator'
9
6
  autoload :CucumberGenerator, 'generators/daemon_kit/cucumber/cucumber_generator'
10
7
  autoload :AmqpGenerator, 'generators/daemon_kit/amqp/amqp_generator'
8
+ autoload :SqsGenerator, 'generators/daemon_kit/sqs/sqs_generator'
11
9
  autoload :CronGenerator, 'generators/daemon_kit/cron/cron_generator'
12
10
  autoload :CapistranoGenerator, 'generators/daemon_kit/capistrano/capistrano_generator'
13
11
  autoload :NaniteAgentGenerator, 'generators/daemon_kit/nanite_agent/nanite_agent_generator'
@@ -241,8 +241,11 @@ module DaemonKit
241
241
  # Duplicate log data to stdout
242
242
  attr_accessor :log_stdout
243
243
 
244
+ # Process instance number, defaults to 1
245
+ attr_accessor :instance
246
+
244
247
  # Path to the pid file, defaults to 'log/<daemon_name>.pid'
245
- attr_accessor :pid_file
248
+ attr_writer :pid_file
246
249
 
247
250
  # The application name
248
251
  configurable :daemon_name, :locked => true
@@ -322,8 +325,12 @@ module DaemonKit
322
325
  @shutdown_hooks << ( proc || block )
323
326
  end
324
327
 
325
- def pid_file
326
- @pid_file ||= "#{File.dirname(self.log_path)}/#{self.daemon_name}.pid"
328
+ def pid_file( instance = nil )
329
+ @pid_file ||= "#{File.dirname(self.log_path)}/#{self.daemon_name}.#{instance}.pid"
330
+ end
331
+
332
+ def instance
333
+ @instance ||= 1
327
334
  end
328
335
 
329
336
  # Set the log level
@@ -1,6 +1,6 @@
1
1
  module DaemonKit
2
2
  def version
3
- '0.1.8.2'
3
+ '0.2.0'
4
4
  end
5
5
  module_function :version
6
6
  end
@@ -17,17 +17,15 @@ end
17
17
  # daemon won't work as advertised.
18
18
 
19
19
  # Run an event-loop for processing
20
- DaemonKit::AMQP.run do
20
+ DaemonKit::AMQP.run do |connection|
21
21
  # Inside this block we're running inside the reactor setup by the
22
22
  # amqp gem. Any code in the examples (from the gem) would work just
23
23
  # fine here.
24
24
 
25
25
  # Uncomment this for connection keep-alive
26
- # AMQP.conn.connection_status do |status|
26
+ # connection.on_tcp_connection_loss do |client, settings|
27
27
  # DaemonKit.logger.debug("AMQP connection status changed: #{status}")
28
- # if status == :disconnected
29
- # AMQP.conn.reconnect(true)
30
- # end
28
+ # client.reconnect(false, 1)
31
29
  # end
32
30
 
33
31
  amq = AMQP::Channel.new
@@ -1,7 +1,7 @@
1
1
  module DaemonKit
2
2
  module Generators
3
3
  class AppGenerator < Base
4
- INSTALLERS = %w( default amqp cron nanite_agent ruote xmpp )
4
+ INSTALLERS = %w( default amqp sqs cron nanite_agent ruote xmpp )
5
5
  DEPLOYERS = %w( capistrano )
6
6
  TEST_FRAMEWORKS = %w( none rspec test_unit )
7
7
  add_shebang_option!
@@ -93,6 +93,8 @@ module DaemonKit
93
93
  directory 'libexec'
94
94
  when 'amqp'
95
95
  invoke DaemonKit::Generators::AmqpGenerator
96
+ when 'sqs'
97
+ invoke DaemonKit::Generators::SqsGenerator
96
98
  when 'cron'
97
99
  invoke DaemonKit::Generators::CronGenerator
98
100
  when 'nanite_agent'
@@ -3,6 +3,8 @@
3
3
  # 'bundle install' to get them all installed. Daemon-kit's capistrano
4
4
  # deployment will ensure that the bundle required by your daemon is properly
5
5
  # installed.
6
+ #
7
+ # For more information on bundler, please visit http://gembundler.com
6
8
 
7
9
  source :gemcutter
8
10
 
@@ -13,5 +15,3 @@ gem 'daemon-kit'
13
15
  gem 'safely'
14
16
  # gem 'toadhopper' # For reporting exceptions to hoptoad
15
17
  # gem 'mail' # For reporting exceptions via mail
16
-
17
- # For more information on bundler, please visit http://gembundler.com
@@ -34,6 +34,13 @@ vendor/
34
34
  tmp/
35
35
  Scratch folder
36
36
 
37
+ Rake Tasks
38
+ ==========
39
+
40
+ Note that the Rakefile does not load the `config/environments.rb` file, so if you have
41
+ environment-specific tasks (such as tests), you will need to call rake with the environment:
42
+
43
+ DAEMON_ENV=staging bundle exec rake -T
37
44
 
38
45
  Logging
39
46
  =======
@@ -6,7 +6,7 @@
6
6
  # Boot up
7
7
  require File.join(File.dirname(__FILE__), 'boot')
8
8
 
9
- # Auto-require default libraries and those for the current Rails environment.
9
+ # Auto-require default libraries and those for the current ruby environment.
10
10
  Bundler.require :default, DaemonKit.env
11
11
 
12
12
  DaemonKit::Initializer.run do |config|
@@ -2,6 +2,16 @@ module DaemonKit
2
2
  module Generators
3
3
  class SpecGenerator < Base
4
4
 
5
+ def update_gemfile
6
+ append_file 'Gemfile', "group :development, :test do\n gem 'rspec'\nend\n"
7
+ append_file 'Gemfile', <<-GEM
8
+ group :development, :test do
9
+ gem 'rake'
10
+ gem 'rspec'
11
+ end
12
+ GEM
13
+ end
14
+
5
15
  def create_specs
6
16
  directory 'spec'
7
17
  end
@@ -1,17 +1,16 @@
1
1
  DAEMON_ENV = 'test' unless defined?( DAEMON_ENV )
2
2
 
3
3
  begin
4
- require 'spec'
4
+ require 'rspec'
5
5
  rescue LoadError
6
6
  require 'rubygems'
7
- gem 'rspec'
8
- require 'spec'
7
+ require 'rspec'
9
8
  end
10
9
 
11
10
  require File.dirname(__FILE__) + '/../config/environment'
12
11
  DaemonKit::Application.running!
13
12
 
14
- Spec::Runner.configure do |config|
13
+ RSpec.configure do |config|
15
14
  # == Mock Framework
16
15
  #
17
16
  # RSpec uses it's own mocking framework by default. If you prefer to
@@ -1,21 +1,13 @@
1
- begin
2
- require 'spec'
3
- require 'spec/rake/spectask'
4
- rescue LoadError
5
- puts <<-EOS
6
- To use rspec for testing you must install rspec gem:
7
- gem install rspec
8
- EOS
9
- end
10
-
11
- begin
12
- require 'spec/rake/spectask'
1
+ if ['test', 'development'].include?(DAEMON_ENV)
2
+ require 'rspec'
3
+ require 'rspec/core/rake_task'
13
4
 
14
5
  desc "Run the specs under spec/"
15
- Spec::Rake::SpecTask.new do |t|
16
- t.spec_opts = ['--options', "spec/spec.opts"]
17
- t.spec_files = FileList['spec/**/*_spec.rb']
6
+ RSpec::Core::RakeTask.new do |t|
7
+ t.rspec_opts = ['--options', "spec/spec.opts"]
18
8
  end
19
- rescue NameError, LoadError
20
- # No loss, warning printed already
9
+
10
+ # Want other tests/tasks run by default?
11
+ # Add them to the list
12
+ task :default => [:spec] #, :features]
21
13
  end
@@ -0,0 +1,5 @@
1
+ Description:
2
+
3
+
4
+ Usage:
5
+
@@ -0,0 +1,24 @@
1
+ module DaemonKit
2
+ module Generators
3
+ class SqsGenerator < Base
4
+
5
+ def update_gemfile
6
+ append_file 'Gemfile', "gem 'aws-sdk'\n"
7
+ end
8
+
9
+ def create_config_files
10
+ directory 'config'
11
+ end
12
+
13
+ def create_daemon
14
+ directory 'libexec'
15
+ end
16
+
17
+ protected
18
+
19
+ def self.source_root
20
+ File.expand_path( File.join( File.dirname(__FILE__), 'templates') )
21
+ end
22
+ end
23
+ end
24
+ end