kennethkalmer-daemon-kit 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +6 -0
- data/Manifest.txt +13 -9
- data/README.textile +19 -2
- data/TODO.txt +1 -1
- data/app_generators/daemon_kit/daemon_kit_generator.rb +2 -3
- data/daemon_generators/amqp/USAGE +5 -0
- data/daemon_generators/amqp/amqp_generator.rb +65 -0
- data/daemon_generators/amqp/templates/config/amqp.yml +28 -0
- data/daemon_generators/amqp/templates/config/initializers/amqp.rb +7 -0
- data/daemon_generators/amqp/templates/libexec/daemon.rb +29 -0
- data/daemon_generators/cron/USAGE +5 -0
- data/daemon_generators/cron/cron_generator.rb +64 -0
- data/daemon_generators/cron/templates/config/initializers/cron.rb +7 -0
- data/daemon_generators/cron/templates/libexec/daemon.rb +39 -0
- data/daemon_generators/jabber/templates/config/initializers/jabber.rb +0 -1
- data/lib/daemon_kit.rb +7 -4
- data/lib/daemon_kit/amqp.rb +41 -0
- data/lib/daemon_kit/application.rb +8 -6
- data/lib/daemon_kit/cron.rb +38 -0
- data/lib/daemon_kit/initializer.rb +6 -0
- data/rubygems_generators/install_rspec/templates/spec/spec_helper.rb +1 -1
- data/test/test_amqp_generator.rb +48 -0
- data/test/test_cron_generator.rb +45 -0
- metadata +29 -15
data/History.txt
CHANGED
data/Manifest.txt
CHANGED
@@ -17,17 +17,24 @@ app_generators/daemon_kit/templates/config/environments/test.rb
|
|
17
17
|
app_generators/daemon_kit/templates/config/initializers/readme
|
18
18
|
app_generators/daemon_kit/templates/libexec/daemon.erb
|
19
19
|
bin/daemon_kit
|
20
|
-
|
20
|
+
daemon_generators/amqp/USAGE
|
21
|
+
daemon_generators/amqp/amqp_generator.rb
|
22
|
+
daemon_generators/amqp/templates/config/amqp.yml
|
23
|
+
daemon_generators/amqp/templates/config/initializers/amqp.rb
|
24
|
+
daemon_generators/amqp/templates/libexec/daemon.rb
|
25
|
+
daemon_generators/cron/USAGE
|
26
|
+
daemon_generators/cron/cron_generator.rb
|
27
|
+
daemon_generators/cron/templates/config/initializers/cron.rb
|
28
|
+
daemon_generators/cron/templates/libexec/daemon.rb
|
21
29
|
daemon_generators/jabber/USAGE
|
22
30
|
daemon_generators/jabber/jabber_generator.rb
|
23
31
|
daemon_generators/jabber/templates/config/initializers/jabber.rb
|
24
32
|
daemon_generators/jabber/templates/config/jabber.yml
|
25
33
|
daemon_generators/jabber/templates/libexec/daemon.rb
|
26
|
-
features/development.feature
|
27
|
-
features/steps/common.rb
|
28
|
-
features/steps/env.rb
|
29
34
|
lib/daemon_kit.rb
|
35
|
+
lib/daemon_kit/amqp.rb
|
30
36
|
lib/daemon_kit/application.rb
|
37
|
+
lib/daemon_kit/cron.rb
|
31
38
|
lib/daemon_kit/initializer.rb
|
32
39
|
lib/daemon_kit/jabber.rb
|
33
40
|
lib/daemon_kit/patches/force_kill_wait.rb
|
@@ -48,11 +55,8 @@ spec/initializer_spec.rb
|
|
48
55
|
spec/spec.opts
|
49
56
|
spec/spec_helper.rb
|
50
57
|
tasks/rspec.rake
|
58
|
+
test/test_amqp_generator.rb
|
59
|
+
test/test_cron_generator.rb
|
51
60
|
test/test_daemon-kit_generator.rb
|
52
61
|
test/test_generator_helper.rb
|
53
62
|
test/test_jabber_generator.rb
|
54
|
-
website/index.html
|
55
|
-
website/index.txt
|
56
|
-
website/javascripts/rounded_corners_lite.inc.js
|
57
|
-
website/stylesheets/screen.css
|
58
|
-
website/template.html.erb
|
data/README.textile
CHANGED
@@ -35,16 +35,33 @@ Currently only two generators exist, a 'default' generator and a 'jabber' genera
|
|
35
35
|
|
36
36
|
The default generator creates a simple daemon with an infinite loop inside that you can adapt.
|
37
37
|
|
38
|
+
h3. Jabber Generator
|
39
|
+
|
38
40
|
The jabber generator creates a simple daemon that leverages the "xmpp4r-simple":http://xmpp4r-simple.rubyforge.org/ gem to process inbound messages. The daemon will manage the roster and other little tasks, leaving you to provide the hooks for processing messages, presence notifications and subscription request.
|
39
41
|
|
42
|
+
h3. Cron Generator
|
43
|
+
|
44
|
+
The cron generator creates a simple daemon that leverages the "rufus-scheduler":http://github.com/jmettraux/rufus-scheduler gem to create a simple cron-lie daemon. Please be aware that this daemon could never be a replacement for the battle-tested "cron utility":http://www.gentoo.org/doc/en/cron-guide.xml shipped standard with most *nix distributions.
|
45
|
+
|
46
|
+
h3. AMQP Consumer Generator
|
47
|
+
|
48
|
+
The AMQP generator creates a simple daemon that has all the stub code and configuration in place to help you write AMQP consumers quickly and effectively. The generated daemon relies on the presence of the "amqp":http://github.com/tmm1/amqp gem.
|
49
|
+
|
40
50
|
h2. Requirements
|
41
51
|
|
42
52
|
* Ruby 1.8.6
|
43
53
|
* daemons 1.0.10
|
44
|
-
* xmpp4r-simple 0.8.8 (if using the 'jabber' generator)
|
45
|
-
* eventmachine 0.12.2 (if using any of the evented generators)
|
46
54
|
* rspec 1.1.11 (for writing/running your specs)
|
47
55
|
|
56
|
+
h3. Generator Requirements
|
57
|
+
|
58
|
+
Depending on the generator you choose for your daemon, it might require additional gems to run.
|
59
|
+
|
60
|
+
|.Generator|.Dependencies|
|
61
|
+
|jabber|"xmpp4r-simple":http://xmpp4r-simple.rubyforge.org/|
|
62
|
+
|cron|"rufus-scheduler":http://github.com/jmettraux/rufus-scheduler|
|
63
|
+
|amqp|"amqp":http://github.com/tmm1/amqp|
|
64
|
+
|
48
65
|
h2. Install
|
49
66
|
|
50
67
|
$ git clone git://github.com/kennethkalmer/daemon-kit.git
|
data/TODO.txt
CHANGED
@@ -5,7 +5,7 @@ This is purely a drop in the bucket of what has to come...
|
|
5
5
|
|
6
6
|
* [DONE] Easy way to trap signals
|
7
7
|
* Error handling to the degree Rails does
|
8
|
-
* Easy configuration of an ORM of choice, including patching it if needed (
|
8
|
+
* Easy configuration of an ORM of choice, including patching it if needed (ActiveRecord *cough*)
|
9
9
|
* Improved generators for creating skeleton daemons:
|
10
10
|
* [DONE] Jabber bot
|
11
11
|
* Evented jabber bot
|
@@ -3,10 +3,9 @@ class DaemonKitGenerator < RubiGen::Base
|
|
3
3
|
DEFAULT_SHEBANG = File.join(Config::CONFIG['bindir'],
|
4
4
|
Config::CONFIG['ruby_install_name'])
|
5
5
|
|
6
|
-
VALID_GENERATORS = ['default', 'jabber']
|
6
|
+
VALID_GENERATORS = ['default', 'jabber', 'cron', 'amqp']
|
7
7
|
|
8
|
-
default_options :shebang => DEFAULT_SHEBANG,
|
9
|
-
:author => nil
|
8
|
+
default_options :shebang => DEFAULT_SHEBANG, :author => nil
|
10
9
|
|
11
10
|
attr_reader :daemon_name
|
12
11
|
attr_reader :installer
|
@@ -0,0 +1,65 @@
|
|
1
|
+
class AmqpGenerator < RubiGen::Base
|
2
|
+
|
3
|
+
default_options :author => nil
|
4
|
+
|
5
|
+
attr_reader :name
|
6
|
+
|
7
|
+
def initialize(runtime_args, runtime_options = {})
|
8
|
+
super
|
9
|
+
usage if args.empty?
|
10
|
+
@name = args.shift
|
11
|
+
extract_options
|
12
|
+
end
|
13
|
+
|
14
|
+
def manifest
|
15
|
+
record do |m|
|
16
|
+
# Ensure appropriate folder(s) exists
|
17
|
+
m.directory ''
|
18
|
+
|
19
|
+
# Create stubs
|
20
|
+
# m.template "template.rb.erb", "some_file_after_erb.rb"
|
21
|
+
# m.template_copy_each ["template.rb", "template2.rb"]
|
22
|
+
# m.template_copy_each ["template.rb", "template2.rb"], "some/path"
|
23
|
+
# m.file "file", "some_file_copied"
|
24
|
+
# m.file_copy_each ["path/to/file", "path/to/file2"]
|
25
|
+
# m.file_copy_each ["path/to/file", "path/to/file2"], "some/path"
|
26
|
+
|
27
|
+
# Copy over our configs
|
28
|
+
m.directory 'config'
|
29
|
+
m.template 'config/amqp.yml', 'config/amqp.yml'
|
30
|
+
m.directory 'config/initializers'
|
31
|
+
m.template 'config/initializers/amqp.rb', "config/initializers/#{name}.rb"
|
32
|
+
|
33
|
+
# Copy over our daemon
|
34
|
+
m.directory 'libexec'
|
35
|
+
m.template 'libexec/daemon.rb', "libexec/#{name}.rb"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
protected
|
40
|
+
def banner
|
41
|
+
<<-EOS
|
42
|
+
Creates a ...
|
43
|
+
|
44
|
+
USAGE: #{$0} #{spec.name} name
|
45
|
+
EOS
|
46
|
+
end
|
47
|
+
|
48
|
+
def add_options!(opts)
|
49
|
+
# opts.separator ''
|
50
|
+
# opts.separator 'Options:'
|
51
|
+
# For each option below, place the default
|
52
|
+
# at the top of the file next to "default_options"
|
53
|
+
# opts.on("-a", "--author=\"Your Name\"", String,
|
54
|
+
# "Some comment about this option",
|
55
|
+
# "Default: none") { |o| options[:author] = o }
|
56
|
+
# opts.on("-v", "--version", "Show the #{File.basename($0)} version number and quit.")
|
57
|
+
end
|
58
|
+
|
59
|
+
def extract_options
|
60
|
+
# for each option, extract it into a local variable (and create an "attr_reader :author" at the top)
|
61
|
+
# Templates can access these value via the attr_reader-generated methods, but not the
|
62
|
+
# raw instance variable value.
|
63
|
+
# @author = options[:author]
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# AMQP client configuration file
|
2
|
+
|
3
|
+
# These values will be used to configure the ampq gem, any values
|
4
|
+
# omitted will let the gem use it's own defaults.
|
5
|
+
|
6
|
+
# The configuration specifies the following keys:
|
7
|
+
# * username - Username for the broker
|
8
|
+
# * password - Password for the broker
|
9
|
+
# * host - Hostname where the broker is running
|
10
|
+
# * vhost - Vhost to connect to
|
11
|
+
# * port - Port where the broker is running
|
12
|
+
# * ssl - Use ssl or not
|
13
|
+
# * timeout - Timeout
|
14
|
+
|
15
|
+
defaults: &defaults
|
16
|
+
username: guest
|
17
|
+
password: guest
|
18
|
+
host: localhost
|
19
|
+
vhost: /
|
20
|
+
|
21
|
+
development:
|
22
|
+
<<: *defaults
|
23
|
+
|
24
|
+
test:
|
25
|
+
<<: *defaults
|
26
|
+
|
27
|
+
production:
|
28
|
+
<<: *defaults
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# Generated amqp daemon
|
2
|
+
|
3
|
+
# Do your post daemonization configuration here
|
4
|
+
# At minimum you need just the first line (without the block), or a lot
|
5
|
+
# of strange things might start happening...
|
6
|
+
DaemonKit::Application.running! do |config|
|
7
|
+
# Trap signals with blocks or procs
|
8
|
+
# config.trap( 'INT' ) do
|
9
|
+
# # do something clever
|
10
|
+
# end
|
11
|
+
# config.trap( 'TERM', Proc.new { puts 'Going down' } )
|
12
|
+
end
|
13
|
+
|
14
|
+
# IMPORTANT CONFIGURATION NOTE
|
15
|
+
#
|
16
|
+
# Please review and update 'config/amqp.yml' accordingly or this
|
17
|
+
# daemon won't work as advertised.
|
18
|
+
|
19
|
+
# Run an event-loop for processing
|
20
|
+
DaemonKit::AMQP.run do
|
21
|
+
# Inside this block we're running inside the reactor setup by the
|
22
|
+
# amqp gem. Any code in the examples (from the gem) would work just
|
23
|
+
# fine here.
|
24
|
+
|
25
|
+
amq = ::MQ.new
|
26
|
+
amq.queue('test').subscribe do |msg|
|
27
|
+
DaemonKit.logger.debug "Received message: #{msg.inspect}"
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
class CronGenerator < RubiGen::Base
|
2
|
+
|
3
|
+
default_options :author => nil
|
4
|
+
|
5
|
+
attr_reader :name
|
6
|
+
|
7
|
+
def initialize(runtime_args, runtime_options = {})
|
8
|
+
super
|
9
|
+
usage if args.empty?
|
10
|
+
@name = args.shift
|
11
|
+
extract_options
|
12
|
+
end
|
13
|
+
|
14
|
+
def manifest
|
15
|
+
record do |m|
|
16
|
+
# Ensure appropriate folder(s) exists
|
17
|
+
m.directory ''
|
18
|
+
|
19
|
+
# Create stubs
|
20
|
+
# m.template "template.rb.erb", "some_file_after_erb.rb"
|
21
|
+
# m.template_copy_each ["template.rb", "template2.rb"]
|
22
|
+
# m.template_copy_each ["template.rb", "template2.rb"], "some/path"
|
23
|
+
# m.file "file", "some_file_copied"
|
24
|
+
# m.file_copy_each ["path/to/file", "path/to/file2"]
|
25
|
+
# m.file_copy_each ["path/to/file", "path/to/file2"], "some/path"
|
26
|
+
|
27
|
+
# Copy over configs
|
28
|
+
m.directory 'config'
|
29
|
+
m.directory 'config/initializers'
|
30
|
+
m.template 'config/initializers/cron.rb', "config/initializers/#{name}.rb"
|
31
|
+
|
32
|
+
# Copy over our daemon
|
33
|
+
m.directory 'libexec'
|
34
|
+
m.template 'libexec/daemon.rb', "libexec/#{name}.rb"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
protected
|
39
|
+
def banner
|
40
|
+
<<-EOS
|
41
|
+
Creates a ...
|
42
|
+
|
43
|
+
USAGE: #{$0} #{spec.name} name
|
44
|
+
EOS
|
45
|
+
end
|
46
|
+
|
47
|
+
def add_options!(opts)
|
48
|
+
# opts.separator ''
|
49
|
+
# opts.separator 'Options:'
|
50
|
+
# For each option below, place the default
|
51
|
+
# at the top of the file next to "default_options"
|
52
|
+
# opts.on("-a", "--author=\"Your Name\"", String,
|
53
|
+
# "Some comment about this option",
|
54
|
+
# "Default: none") { |o| options[:author] = o }
|
55
|
+
# opts.on("-v", "--version", "Show the #{File.basename($0)} version number and quit.")
|
56
|
+
end
|
57
|
+
|
58
|
+
def extract_options
|
59
|
+
# for each option, extract it into a local variable (and create an "attr_reader :author" at the top)
|
60
|
+
# Templates can access these value via the attr_reader-generated methods, but not the
|
61
|
+
# raw instance variable value.
|
62
|
+
# @author = options[:author]
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# Generated cron daemon
|
2
|
+
|
3
|
+
# Do your post daemonization configuration here
|
4
|
+
# At minimum you need just the first line (without the block), or a lot
|
5
|
+
# of strange things might start happening...
|
6
|
+
DaemonKit::Application.running! do |config|
|
7
|
+
# Trap signals with blocks or procs
|
8
|
+
# config.trap( 'INT' ) do
|
9
|
+
# # do something clever
|
10
|
+
# end
|
11
|
+
# config.trap( 'TERM', Proc.new { puts 'Going down' } )
|
12
|
+
end
|
13
|
+
|
14
|
+
# Configuration documentation available at http://rufus.rubyforge.org/rufus-scheduler/
|
15
|
+
# An instance of the scheduler is available through
|
16
|
+
# DaemonKit::Cron.scheduler
|
17
|
+
|
18
|
+
# Some samples to get you going:
|
19
|
+
|
20
|
+
# Will call #regenerate_monthly_report in 3 days from starting up
|
21
|
+
#DaemonKit::Cron.scheduler.in("3d") do
|
22
|
+
# regenerate_monthly_report()
|
23
|
+
#end
|
24
|
+
#
|
25
|
+
#DaemonKit::Cron.scheduler.every "10m10s" do
|
26
|
+
# check_score(favourite_team) # every 10 minutes and 10 seconds
|
27
|
+
#end
|
28
|
+
#
|
29
|
+
#DaemonKit::Cron.scheduler.cron "0 22 * * 1-5" do
|
30
|
+
# log.info "activating security system..."
|
31
|
+
# activate_security_system()
|
32
|
+
#end
|
33
|
+
|
34
|
+
DaemonKit::Cron.scheduler.every("1m") do
|
35
|
+
DaemonKit.logger.debug "Scheduled task completed at #{Time.now}"
|
36
|
+
end
|
37
|
+
|
38
|
+
# Run our 'cron' daeon
|
39
|
+
DaemonKit::Cron.run
|
data/lib/daemon_kit.rb
CHANGED
@@ -3,9 +3,12 @@ $:.unshift(File.dirname(__FILE__)) unless
|
|
3
3
|
|
4
4
|
require 'rubygems'
|
5
5
|
|
6
|
-
require 'daemon_kit/initializer'
|
7
|
-
require 'daemon_kit/application'
|
8
|
-
|
9
6
|
module DaemonKit
|
10
|
-
VERSION = '0.1.
|
7
|
+
VERSION = '0.1.1'
|
8
|
+
|
9
|
+
autoload :Initializer, 'daemon_kit/initializer'
|
10
|
+
autoload :Application, 'daemon_kit/application'
|
11
|
+
autoload :Cron, 'daemon_kit/cron'
|
12
|
+
autoload :Jabber, 'daemon_kit/jabber'
|
13
|
+
autoload :AMQP, 'daemon_kit/amqp'
|
11
14
|
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module DaemonKit
|
4
|
+
# Thin wrapper around the amqp gem, specifically designed to ease
|
5
|
+
# configuration of a AMQP consumer daemon and provide some added
|
6
|
+
# simplicity
|
7
|
+
class AMQP
|
8
|
+
|
9
|
+
@@instance = nil
|
10
|
+
|
11
|
+
class << self
|
12
|
+
|
13
|
+
def instance
|
14
|
+
@instance ||= (
|
15
|
+
config = YAML.load_file( "#{DAEMON_ROOT}/config/amqp.yml" )[DAEMON_ENV]
|
16
|
+
raise ArgumentError, "Missing AMQP configuration for #{DAEMON_ENV} environment" if config.nil?
|
17
|
+
new( config )
|
18
|
+
)
|
19
|
+
end
|
20
|
+
|
21
|
+
private :new
|
22
|
+
|
23
|
+
def run(&block)
|
24
|
+
instance.run(&block)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def initialize( config = {} )
|
29
|
+
@config = config.inject({}) { |m,c| m[c[0].to_sym] = c[1]; m } # symbolize_keys
|
30
|
+
end
|
31
|
+
|
32
|
+
def run(&block)
|
33
|
+
# Ensure graceful shutdown of the connection to the broker
|
34
|
+
DaemonKit.trap('INT') { ::AMQP.stop { ::EM.stop } }
|
35
|
+
DaemonKit.trap('TERM') { ::AMQP.stop { ::EM.stop } }
|
36
|
+
|
37
|
+
# Start our event loop
|
38
|
+
::AMQP.start(@config, &block)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -6,27 +6,29 @@ module DaemonKit
|
|
6
6
|
class Application
|
7
7
|
|
8
8
|
class << self
|
9
|
-
|
9
|
+
|
10
10
|
# Run the file as a daemon
|
11
11
|
def run( file )
|
12
12
|
raise DaemonNotFound.new( file ) unless File.exist?( file )
|
13
|
-
|
13
|
+
|
14
14
|
app_name = DaemonKit.configuration.daemon_name || File.basename( file )
|
15
15
|
options = { :backtrace => true, :log_output => true, :app_name => app_name }
|
16
16
|
|
17
|
-
options[:
|
17
|
+
options[:dir_mode] = DaemonKit.configuration.dir_mode || :normal
|
18
|
+
options[:dir] = DaemonKit.configuration.dir || "log"
|
19
|
+
options[:multiple] = DaemonKit.configuration.multiple
|
18
20
|
options[:force_kill_wait] = DaemonKit.configuration.force_kill_wait if DaemonKit.configuration.force_kill_wait
|
19
21
|
|
20
22
|
Daemons.run( file, options )
|
21
23
|
end
|
22
|
-
|
24
|
+
|
23
25
|
# Call this from inside a daemonized process to complete the
|
24
26
|
# initialization process
|
25
27
|
def running!
|
26
28
|
DaemonKit::Initializer.continue!
|
27
29
|
end
|
28
|
-
|
30
|
+
|
29
31
|
end
|
30
|
-
|
32
|
+
|
31
33
|
end
|
32
34
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module DaemonKit
|
2
|
+
|
3
|
+
# Thin wrapper around rufus-scheduler gem, specifically designed to ease
|
4
|
+
# configuration of a scheduler and provide some added simplicity.
|
5
|
+
class Cron
|
6
|
+
|
7
|
+
@@instance = nil
|
8
|
+
|
9
|
+
attr_reader :scheduler
|
10
|
+
|
11
|
+
class << self
|
12
|
+
|
13
|
+
def instance
|
14
|
+
@instance ||= new
|
15
|
+
end
|
16
|
+
|
17
|
+
def scheduler
|
18
|
+
instance.scheduler
|
19
|
+
end
|
20
|
+
|
21
|
+
private :new
|
22
|
+
|
23
|
+
def run
|
24
|
+
DaemonKit.logger.info "Starting rufus-scheduler"
|
25
|
+
|
26
|
+
begin
|
27
|
+
instance.scheduler.join
|
28
|
+
rescue Interrupt
|
29
|
+
DaemonKit.logger.warn "Scheduler interrupted"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def initialize
|
35
|
+
@scheduler = Rufus::Scheduler.start_new
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -145,6 +145,12 @@ module DaemonKit
|
|
145
145
|
# Path to the log file, defaults to 'log/<environment>.log'
|
146
146
|
attr_accessor :log_path
|
147
147
|
|
148
|
+
# :system,
|
149
|
+
attr_accessor :dir_mode
|
150
|
+
|
151
|
+
# Path to the log file, defaults to 'log/<environment>.log'
|
152
|
+
attr_accessor :dir
|
153
|
+
|
148
154
|
# Provide a custom logger to use
|
149
155
|
attr_accessor :logger
|
150
156
|
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "test_generator_helper.rb")
|
2
|
+
|
3
|
+
|
4
|
+
class TestAmqpGenerator < Test::Unit::TestCase
|
5
|
+
include RubiGen::GeneratorTestHelper
|
6
|
+
|
7
|
+
def setup
|
8
|
+
bare_setup
|
9
|
+
end
|
10
|
+
|
11
|
+
def teardown
|
12
|
+
bare_teardown
|
13
|
+
end
|
14
|
+
|
15
|
+
# Some generator-related assertions:
|
16
|
+
# assert_generated_file(name, &block) # block passed the file contents
|
17
|
+
# assert_directory_exists(name)
|
18
|
+
# assert_generated_class(name, &block)
|
19
|
+
# assert_generated_module(name, &block)
|
20
|
+
# assert_generated_test_for(name, &block)
|
21
|
+
# The assert_generated_(class|module|test_for) &block is passed the body of the class/module within the file
|
22
|
+
# assert_has_method(body, *methods) # check that the body has a list of methods (methods with parentheses not supported yet)
|
23
|
+
#
|
24
|
+
# Other helper methods are:
|
25
|
+
# app_root_files - put this in teardown to show files generated by the test method (e.g. p app_root_files)
|
26
|
+
# bare_setup - place this in setup method to create the APP_ROOT folder for each test
|
27
|
+
# bare_teardown - place this in teardown method to destroy the TMP_ROOT or APP_ROOT folder after each test
|
28
|
+
|
29
|
+
def test_generator_without_options
|
30
|
+
name = "myapp"
|
31
|
+
run_generator('amqp', [name], sources)
|
32
|
+
assert_directory_exists "config"
|
33
|
+
assert_directory_exists "config/initializers"
|
34
|
+
assert_generated_file "config/amqp.yml"
|
35
|
+
assert_generated_file "config/initializers/myapp.rb"
|
36
|
+
assert_generated_file "libexec/myapp.rb"
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
def sources
|
41
|
+
[RubiGen::PathSource.new(:test, File.join(File.dirname(__FILE__),"..", generator_path))
|
42
|
+
]
|
43
|
+
end
|
44
|
+
|
45
|
+
def generator_path
|
46
|
+
"daemon_generators"
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "test_generator_helper.rb")
|
2
|
+
|
3
|
+
|
4
|
+
class TestCronGenerator < Test::Unit::TestCase
|
5
|
+
include RubiGen::GeneratorTestHelper
|
6
|
+
|
7
|
+
def setup
|
8
|
+
bare_setup
|
9
|
+
end
|
10
|
+
|
11
|
+
def teardown
|
12
|
+
bare_teardown
|
13
|
+
end
|
14
|
+
|
15
|
+
# Some generator-related assertions:
|
16
|
+
# assert_generated_file(name, &block) # block passed the file contents
|
17
|
+
# assert_directory_exists(name)
|
18
|
+
# assert_generated_class(name, &block)
|
19
|
+
# assert_generated_module(name, &block)
|
20
|
+
# assert_generated_test_for(name, &block)
|
21
|
+
# The assert_generated_(class|module|test_for) &block is passed the body of the class/module within the file
|
22
|
+
# assert_has_method(body, *methods) # check that the body has a list of methods (methods with parentheses not supported yet)
|
23
|
+
#
|
24
|
+
# Other helper methods are:
|
25
|
+
# app_root_files - put this in teardown to show files generated by the test method (e.g. p app_root_files)
|
26
|
+
# bare_setup - place this in setup method to create the APP_ROOT folder for each test
|
27
|
+
# bare_teardown - place this in teardown method to destroy the TMP_ROOT or APP_ROOT folder after each test
|
28
|
+
|
29
|
+
def test_generator_without_options
|
30
|
+
name = "myapp"
|
31
|
+
run_generator('cron', [name], sources)
|
32
|
+
assert_directory_exists "config/initializers"
|
33
|
+
assert_generated_file "config/initializers/myapp.rb"
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
def sources
|
38
|
+
[RubiGen::PathSource.new(:test, File.join(File.dirname(__FILE__),"..", generator_path))
|
39
|
+
]
|
40
|
+
end
|
41
|
+
|
42
|
+
def generator_path
|
43
|
+
"daemon_generators"
|
44
|
+
end
|
45
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kennethkalmer-daemon-kit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kenneth Kalmer
|
@@ -9,11 +9,12 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-04-27 00:00:00 -07:00
|
13
13
|
default_executable: daemon_kit
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: daemons
|
17
|
+
type: :runtime
|
17
18
|
version_requirement:
|
18
19
|
version_requirements: !ruby/object:Gem::Requirement
|
19
20
|
requirements:
|
@@ -23,15 +24,17 @@ dependencies:
|
|
23
24
|
version:
|
24
25
|
- !ruby/object:Gem::Dependency
|
25
26
|
name: newgem
|
27
|
+
type: :development
|
26
28
|
version_requirement:
|
27
29
|
version_requirements: !ruby/object:Gem::Requirement
|
28
30
|
requirements:
|
29
31
|
- - ">="
|
30
32
|
- !ruby/object:Gem::Version
|
31
|
-
version: 1.
|
33
|
+
version: 1.3.0
|
32
34
|
version:
|
33
35
|
- !ruby/object:Gem::Dependency
|
34
36
|
name: hoe
|
37
|
+
type: :development
|
35
38
|
version_requirement:
|
36
39
|
version_requirements: !ruby/object:Gem::Requirement
|
37
40
|
requirements:
|
@@ -51,7 +54,6 @@ extra_rdoc_files:
|
|
51
54
|
- Manifest.txt
|
52
55
|
- PostInstall.txt
|
53
56
|
- TODO.txt
|
54
|
-
- website/index.txt
|
55
57
|
files:
|
56
58
|
- History.txt
|
57
59
|
- Manifest.txt
|
@@ -72,17 +74,24 @@ files:
|
|
72
74
|
- app_generators/daemon_kit/templates/config/initializers/readme
|
73
75
|
- app_generators/daemon_kit/templates/libexec/daemon.erb
|
74
76
|
- bin/daemon_kit
|
75
|
-
-
|
77
|
+
- daemon_generators/amqp/USAGE
|
78
|
+
- daemon_generators/amqp/amqp_generator.rb
|
79
|
+
- daemon_generators/amqp/templates/config/amqp.yml
|
80
|
+
- daemon_generators/amqp/templates/config/initializers/amqp.rb
|
81
|
+
- daemon_generators/amqp/templates/libexec/daemon.rb
|
82
|
+
- daemon_generators/cron/USAGE
|
83
|
+
- daemon_generators/cron/cron_generator.rb
|
84
|
+
- daemon_generators/cron/templates/config/initializers/cron.rb
|
85
|
+
- daemon_generators/cron/templates/libexec/daemon.rb
|
76
86
|
- daemon_generators/jabber/USAGE
|
77
87
|
- daemon_generators/jabber/jabber_generator.rb
|
78
88
|
- daemon_generators/jabber/templates/config/initializers/jabber.rb
|
79
89
|
- daemon_generators/jabber/templates/config/jabber.yml
|
80
90
|
- daemon_generators/jabber/templates/libexec/daemon.rb
|
81
|
-
- features/development.feature
|
82
|
-
- features/steps/common.rb
|
83
|
-
- features/steps/env.rb
|
84
91
|
- lib/daemon_kit.rb
|
92
|
+
- lib/daemon_kit/amqp.rb
|
85
93
|
- lib/daemon_kit/application.rb
|
94
|
+
- lib/daemon_kit/cron.rb
|
86
95
|
- lib/daemon_kit/initializer.rb
|
87
96
|
- lib/daemon_kit/jabber.rb
|
88
97
|
- lib/daemon_kit/patches/force_kill_wait.rb
|
@@ -103,17 +112,20 @@ files:
|
|
103
112
|
- spec/spec.opts
|
104
113
|
- spec/spec_helper.rb
|
105
114
|
- tasks/rspec.rake
|
115
|
+
- test/test_amqp_generator.rb
|
116
|
+
- test/test_cron_generator.rb
|
106
117
|
- test/test_daemon-kit_generator.rb
|
107
118
|
- test/test_generator_helper.rb
|
108
119
|
- test/test_jabber_generator.rb
|
109
|
-
- website/index.html
|
110
|
-
- website/index.txt
|
111
|
-
- website/javascripts/rounded_corners_lite.inc.js
|
112
|
-
- website/stylesheets/screen.css
|
113
|
-
- website/template.html.erb
|
114
120
|
has_rdoc: true
|
115
121
|
homepage:
|
116
|
-
post_install_message:
|
122
|
+
post_install_message: |+
|
123
|
+
|
124
|
+
For more information on daemon-kit, see http://daemon-kit.rubyforge.org
|
125
|
+
|
126
|
+
To get started quickly run 'daemon_kit' without any arguments
|
127
|
+
|
128
|
+
|
117
129
|
rdoc_options:
|
118
130
|
- --main
|
119
131
|
- README.textile
|
@@ -139,6 +151,8 @@ signing_key:
|
|
139
151
|
specification_version: 2
|
140
152
|
summary: Daemon Kit aims to simplify creating Ruby daemons by providing a sound application skeleton (through a generator), task specific generators (jabber bot, etc) and robust environment management code.
|
141
153
|
test_files:
|
142
|
-
- test/test_jabber_generator.rb
|
143
154
|
- test/test_daemon-kit_generator.rb
|
144
155
|
- test/test_generator_helper.rb
|
156
|
+
- test/test_jabber_generator.rb
|
157
|
+
- test/test_cron_generator.rb
|
158
|
+
- test/test_amqp_generator.rb
|