queso-daemon-kit 0.1.7.10
Sign up to get free protection for your applications and to get access to all the features.
- data/Configuration.txt +110 -0
- data/Deployment.txt +113 -0
- data/History.txt +97 -0
- data/Logging.txt +92 -0
- data/Manifest.txt +166 -0
- data/PostInstall.txt +6 -0
- data/README.rdoc +130 -0
- data/Rakefile +37 -0
- data/RuoteParticipants.txt +113 -0
- data/TODO.txt +37 -0
- data/app_generators/daemon_kit/USAGE +7 -0
- data/app_generators/daemon_kit/daemon_kit_generator.rb +161 -0
- data/app_generators/daemon_kit/templates/README +48 -0
- data/app_generators/daemon_kit/templates/Rakefile +6 -0
- data/app_generators/daemon_kit/templates/bin/daemon.erb +7 -0
- data/app_generators/daemon_kit/templates/config/arguments.rb +12 -0
- data/app_generators/daemon_kit/templates/config/boot.rb +68 -0
- data/app_generators/daemon_kit/templates/config/environment.rb +23 -0
- data/app_generators/daemon_kit/templates/config/environments/development.rb +2 -0
- data/app_generators/daemon_kit/templates/config/environments/production.rb +2 -0
- data/app_generators/daemon_kit/templates/config/environments/test.rb +2 -0
- data/app_generators/daemon_kit/templates/config/post-daemonize/readme +5 -0
- data/app_generators/daemon_kit/templates/config/pre-daemonize/readme +12 -0
- data/app_generators/daemon_kit/templates/lib/daemon.rb +2 -0
- data/app_generators/daemon_kit/templates/libexec/daemon.erb +18 -0
- data/app_generators/daemon_kit/templates/script/console +3 -0
- data/app_generators/daemon_kit/templates/script/destroy +14 -0
- data/app_generators/daemon_kit/templates/script/generate +14 -0
- data/bin/daemon_kit +18 -0
- 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 +37 -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 +11 -0
- data/daemon_generators/cron/templates/libexec/daemon.rb +43 -0
- data/daemon_generators/cucumber/USAGE +11 -0
- data/daemon_generators/cucumber/cucumber_generator.rb +38 -0
- data/daemon_generators/cucumber/templates/cucumber +8 -0
- data/daemon_generators/cucumber/templates/cucumber.rake +13 -0
- data/daemon_generators/cucumber/templates/cucumber_environment.rb +2 -0
- data/daemon_generators/cucumber/templates/env.rb +7 -0
- data/daemon_generators/deploy_capistrano/deploy_capistrano_generator.rb +35 -0
- data/daemon_generators/deploy_capistrano/templates/Capfile +10 -0
- data/daemon_generators/deploy_capistrano/templates/USAGE +10 -0
- data/daemon_generators/deploy_capistrano/templates/config/deploy.rb +53 -0
- data/daemon_generators/deploy_capistrano/templates/config/deploy/production.rb +6 -0
- data/daemon_generators/deploy_capistrano/templates/config/deploy/staging.rb +6 -0
- data/daemon_generators/deploy_capistrano/templates/config/environments/staging.rb +0 -0
- data/daemon_generators/jabber/USAGE +5 -0
- data/daemon_generators/jabber/jabber_generator.rb +65 -0
- data/daemon_generators/jabber/templates/config/initializers/jabber.rb +7 -0
- data/daemon_generators/jabber/templates/config/jabber.yml +26 -0
- data/daemon_generators/jabber/templates/libexec/daemon.rb +27 -0
- data/daemon_generators/nanite_agent/USAGE +5 -0
- data/daemon_generators/nanite_agent/nanite_agent_generator.rb +68 -0
- data/daemon_generators/nanite_agent/templates/config/initializers/nanite_agent.rb +6 -0
- data/daemon_generators/nanite_agent/templates/config/nanite.yml +35 -0
- data/daemon_generators/nanite_agent/templates/lib/actors/sample.rb +11 -0
- data/daemon_generators/nanite_agent/templates/libexec/daemon.rb +31 -0
- data/daemon_generators/rspec/USAGE +5 -0
- data/daemon_generators/rspec/rspec_generator.rb +55 -0
- data/daemon_generators/rspec/templates/spec.rb +11 -0
- data/daemon_generators/rspec/templates/spec/spec.opts +1 -0
- data/daemon_generators/rspec/templates/spec/spec_helper.rb +21 -0
- data/daemon_generators/rspec/templates/tasks/rspec.rake +21 -0
- data/daemon_generators/ruote/USAGE +5 -0
- data/daemon_generators/ruote/ruote_generator.rb +67 -0
- data/daemon_generators/ruote/templates/config/amqp.yml +30 -0
- data/daemon_generators/ruote/templates/config/initializers/ruote.rb +13 -0
- data/daemon_generators/ruote/templates/config/ruote.yml +23 -0
- data/daemon_generators/ruote/templates/lib/daemon.rb +4 -0
- data/daemon_generators/ruote/templates/lib/sample.rb +26 -0
- data/daemon_generators/ruote/templates/libexec/daemon.rb +33 -0
- data/lib/daemon_kit.rb +62 -0
- data/lib/daemon_kit/abstract_logger.rb +235 -0
- data/lib/daemon_kit/amqp.rb +38 -0
- data/lib/daemon_kit/application.rb +187 -0
- data/lib/daemon_kit/arguments.rb +165 -0
- data/lib/daemon_kit/commands/console.rb +38 -0
- data/lib/daemon_kit/config.rb +108 -0
- data/lib/daemon_kit/console_daemon.rb +2 -0
- data/lib/daemon_kit/core_ext.rb +1 -0
- data/lib/daemon_kit/core_ext/configurable.rb +96 -0
- data/lib/daemon_kit/core_ext/string.rb +22 -0
- data/lib/daemon_kit/cron.rb +48 -0
- data/lib/daemon_kit/cucumber/world.rb +38 -0
- data/lib/daemon_kit/deployment/capistrano.rb +482 -0
- data/lib/daemon_kit/em.rb +43 -0
- data/lib/daemon_kit/error_handlers/base.rb +32 -0
- data/lib/daemon_kit/error_handlers/hoptoad.rb +60 -0
- data/lib/daemon_kit/error_handlers/mail.rb +85 -0
- data/lib/daemon_kit/exceptions.rb +15 -0
- data/lib/daemon_kit/initializer.rb +438 -0
- data/lib/daemon_kit/jabber.rb +170 -0
- data/lib/daemon_kit/nanite.rb +7 -0
- data/lib/daemon_kit/nanite/agent.rb +56 -0
- data/lib/daemon_kit/pid_file.rb +61 -0
- data/lib/daemon_kit/ruote_participants.rb +119 -0
- data/lib/daemon_kit/ruote_pseudo_participant.rb +68 -0
- data/lib/daemon_kit/ruote_workitem.rb +169 -0
- data/lib/daemon_kit/safety.rb +85 -0
- data/lib/daemon_kit/tasks.rb +2 -0
- data/lib/daemon_kit/tasks/environment.rake +10 -0
- data/lib/daemon_kit/tasks/framework.rake +120 -0
- data/lib/daemon_kit/tasks/god.rake +62 -0
- data/lib/daemon_kit/tasks/log.rake +8 -0
- data/lib/daemon_kit/tasks/monit.rake +29 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/script/txt2html +71 -0
- data/spec/abstract_logger_spec.rb +126 -0
- data/spec/argument_spec.rb +70 -0
- data/spec/config_spec.rb +79 -0
- data/spec/configurable_spec.rb +56 -0
- data/spec/daemon_kit_spec.rb +7 -0
- data/spec/error_handlers_spec.rb +23 -0
- data/spec/fixtures/env.yml +15 -0
- data/spec/fixtures/noenv.yml +4 -0
- data/spec/initializer_spec.rb +26 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +27 -0
- data/tasks/rspec.rake +21 -0
- data/templates/god/god.erb +69 -0
- data/templates/monit/monit.erb +14 -0
- data/test/test_amqp_generator.rb +48 -0
- data/test/test_cron_generator.rb +45 -0
- data/test/test_daemon-kit_generator.rb +84 -0
- data/test/test_daemon_kit_config.rb +28 -0
- data/test/test_deploy_capistrano_generator.rb +48 -0
- data/test/test_generator_helper.rb +29 -0
- data/test/test_helper.rb +7 -0
- data/test/test_jabber_generator.rb +49 -0
- data/test/test_nanite_agent_generator.rb +49 -0
- data/test/test_ruote_generator.rb +45 -0
- data/vendor/tmail-1.2.3/tmail.rb +5 -0
- data/vendor/tmail-1.2.3/tmail/address.rb +426 -0
- data/vendor/tmail-1.2.3/tmail/attachments.rb +46 -0
- data/vendor/tmail-1.2.3/tmail/base64.rb +46 -0
- data/vendor/tmail-1.2.3/tmail/compat.rb +41 -0
- data/vendor/tmail-1.2.3/tmail/config.rb +67 -0
- data/vendor/tmail-1.2.3/tmail/core_extensions.rb +63 -0
- data/vendor/tmail-1.2.3/tmail/encode.rb +581 -0
- data/vendor/tmail-1.2.3/tmail/header.rb +960 -0
- data/vendor/tmail-1.2.3/tmail/index.rb +9 -0
- data/vendor/tmail-1.2.3/tmail/interface.rb +1130 -0
- data/vendor/tmail-1.2.3/tmail/loader.rb +3 -0
- data/vendor/tmail-1.2.3/tmail/mail.rb +578 -0
- data/vendor/tmail-1.2.3/tmail/mailbox.rb +495 -0
- data/vendor/tmail-1.2.3/tmail/main.rb +6 -0
- data/vendor/tmail-1.2.3/tmail/mbox.rb +3 -0
- data/vendor/tmail-1.2.3/tmail/net.rb +248 -0
- data/vendor/tmail-1.2.3/tmail/obsolete.rb +132 -0
- data/vendor/tmail-1.2.3/tmail/parser.rb +1476 -0
- data/vendor/tmail-1.2.3/tmail/port.rb +379 -0
- data/vendor/tmail-1.2.3/tmail/quoting.rb +118 -0
- data/vendor/tmail-1.2.3/tmail/require_arch.rb +58 -0
- data/vendor/tmail-1.2.3/tmail/scanner.rb +49 -0
- data/vendor/tmail-1.2.3/tmail/scanner_r.rb +261 -0
- data/vendor/tmail-1.2.3/tmail/stringio.rb +280 -0
- data/vendor/tmail-1.2.3/tmail/utils.rb +337 -0
- data/vendor/tmail-1.2.3/tmail/version.rb +39 -0
- data/vendor/tmail.rb +13 -0
- metadata +281 -0
data/PostInstall.txt
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
= Daemon Kit
|
2
|
+
|
3
|
+
* http://kit.rubyforge.org/daemon-kit/rdoc/
|
4
|
+
* http://kit.rubyforge.org/daemon-kit (coming soon)
|
5
|
+
* http://groups.google.com/group/daemon-kit (daemon-kit@googlegroups.com)
|
6
|
+
* #daemon-kit on Freenode
|
7
|
+
|
8
|
+
== Description
|
9
|
+
|
10
|
+
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.
|
11
|
+
|
12
|
+
Using simple built-in generators it is easy to created evented and non-evented daemons that perform a multitude of different tasks.
|
13
|
+
|
14
|
+
Supported generators:
|
15
|
+
|
16
|
+
* XMPP bot (non-evented)
|
17
|
+
* AMQP consumer (evented)
|
18
|
+
* Nanite agent
|
19
|
+
* Cron-style daemon
|
20
|
+
* ruote remote participants
|
21
|
+
|
22
|
+
== Features/Problems
|
23
|
+
|
24
|
+
* Build it
|
25
|
+
* Review TODO.txt
|
26
|
+
|
27
|
+
== Synopsis
|
28
|
+
|
29
|
+
$ daemon_kit -h
|
30
|
+
|
31
|
+
Get some help
|
32
|
+
|
33
|
+
$ daemon_kit [/path/to/your/daemon] [options]
|
34
|
+
|
35
|
+
The above command generates a skeleton daemon environment for you to adapt.
|
36
|
+
|
37
|
+
$ daemon_kit [/path/to/your/daemon] -i jabber
|
38
|
+
|
39
|
+
Use the 'jabber' generator instead of the default one.
|
40
|
+
|
41
|
+
== Generators
|
42
|
+
|
43
|
+
Currently six generators exist: default, jabber, amqp, cron, nanite & ruote
|
44
|
+
|
45
|
+
The default generator creates a simple daemon with an infinite loop inside that you can adapt.
|
46
|
+
|
47
|
+
=== Jabber Generator
|
48
|
+
|
49
|
+
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.
|
50
|
+
|
51
|
+
=== Cron Generator
|
52
|
+
|
53
|
+
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.
|
54
|
+
|
55
|
+
=== AMQP Consumer Generator
|
56
|
+
|
57
|
+
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.
|
58
|
+
|
59
|
+
=== Nanite Agent Generator
|
60
|
+
|
61
|
+
The "nanite":http://github.com/ezmobius/nanite agent generator gets you up and running with nanite agents very quickly.
|
62
|
+
|
63
|
+
=== ruote Remote Participants
|
64
|
+
|
65
|
+
The "ruote":http://openwfe.rubyforge.org remote participant generator speeds up the development of workflow participants that run outside of the Ruby process that houses the engine. Daemon-kit handles all the communication and delegation logic, allowing you to focus purely on your participant's activities.
|
66
|
+
|
67
|
+
== Requirements
|
68
|
+
|
69
|
+
* Ruby 1.8.6
|
70
|
+
* eventmachine-0.12.8[http://rubyeventmachine.com]
|
71
|
+
* rspec (for writing/running your specs)
|
72
|
+
|
73
|
+
== Generator Requirements
|
74
|
+
|
75
|
+
Depending on the generator you choose for your daemon, it might require additional gems to run.
|
76
|
+
|
77
|
+
* jabber - xmpp4r-simple[http://xmpp4r-simple.rubyforge.org]
|
78
|
+
* cron - rufus-scheduler[http://github.com/jmettraux/rufus-scheduler] (at least version 2.0.0)
|
79
|
+
* amqp - amqp[http://github.com/tmm1/amqp]
|
80
|
+
* nanite - nanite[http://github.com/ezmobius/nanite]
|
81
|
+
* ruote - none, although ruote[http://openwfe.rubyforge.org] should probably be running somewhere
|
82
|
+
|
83
|
+
== Install
|
84
|
+
|
85
|
+
Currently recommended to stick to the git repo:
|
86
|
+
|
87
|
+
$ git clone git://github.com/kennethkalmer/daemon-kit.git
|
88
|
+
$ rake gem
|
89
|
+
$ gem install pkg/daemon-kit-X.X.X.gem
|
90
|
+
|
91
|
+
Development versions are available as gems from github:
|
92
|
+
|
93
|
+
$ gem install kennethkalmer-daemon-kit -s http://gems.github.com
|
94
|
+
|
95
|
+
Stable versions, when released are available directly from Rubyforge:
|
96
|
+
|
97
|
+
$ gem install daemon-kit
|
98
|
+
|
99
|
+
== Further reading
|
100
|
+
|
101
|
+
* Configuration.txt
|
102
|
+
* Deployment.txt
|
103
|
+
* Logging.txt
|
104
|
+
* RuoteParticipants.txt
|
105
|
+
* http://www.opensourcery.co.za/tag/daemon-kit/
|
106
|
+
|
107
|
+
== License
|
108
|
+
|
109
|
+
(The MIT License)
|
110
|
+
|
111
|
+
Copyright (c) 2009 Kenneth Kalmer (Internet Exchange CC, Clear Planet Information Solutions Pty Ltd)
|
112
|
+
|
113
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
114
|
+
a copy of this software and associated documentation files (the
|
115
|
+
'Software'), to deal in the Software without restriction, including
|
116
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
117
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
118
|
+
permit persons to whom the Software is furnished to do so, subject to
|
119
|
+
the following conditions:
|
120
|
+
|
121
|
+
The above copyright notice and this permission notice shall be
|
122
|
+
included in all copies or substantial portions of the Software.
|
123
|
+
|
124
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
125
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
126
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
127
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
128
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
129
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
130
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
gem 'hoe', '>= 2.1.0'
|
3
|
+
require 'hoe'
|
4
|
+
require 'fileutils'
|
5
|
+
require File.dirname(__FILE__) + '/lib/daemon_kit'
|
6
|
+
|
7
|
+
Hoe.plugin :newgem
|
8
|
+
Hoe.plugin :website
|
9
|
+
# Hoe.plugin :cucumberfeatures
|
10
|
+
|
11
|
+
# Generate all the Rake tasks
|
12
|
+
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
13
|
+
$hoe = Hoe.spec('daemon-kit') do |p|
|
14
|
+
p.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.'
|
15
|
+
p.developer('Kenneth Kalmer', 'kenneth.kalmer@gmail.com')
|
16
|
+
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
|
17
|
+
p.post_install_message = IO.read( 'PostInstall.txt' ) # TODO remove if post-install message not required
|
18
|
+
p.rubyforge_name = 'kit' # TODO this is default value
|
19
|
+
p.extra_deps = [
|
20
|
+
['rubigen', '>= 1.5.2'],
|
21
|
+
['eventmachine', '>=0.12.8']
|
22
|
+
]
|
23
|
+
p.extra_dev_deps = [
|
24
|
+
['newgem', ">= #{::Newgem::VERSION}"]
|
25
|
+
]
|
26
|
+
|
27
|
+
p.clean_globs |= %w[**/.DS_Store tmp *.log]
|
28
|
+
path = (p.rubyforge_name == p.name) ? p.rubyforge_name : "\#{p.rubyforge_name}/\#{p.name}"
|
29
|
+
p.remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/,''), 'rdoc')
|
30
|
+
p.rsync_args = '-av --delete --ignore-errors'
|
31
|
+
end
|
32
|
+
|
33
|
+
require 'newgem/tasks' # load /tasks/*.rake
|
34
|
+
Dir['tasks/**/*.rake'].each { |t| load t }
|
35
|
+
|
36
|
+
# TODO - want other tests/tasks run by default? Add them to the list
|
37
|
+
task :default => [:spec] #, :features]
|
@@ -0,0 +1,113 @@
|
|
1
|
+
= Writing remote ruote participants with daemon-kit
|
2
|
+
|
3
|
+
daemon-kit is an ideal housing for remote ruote participants, providing a lot
|
4
|
+
of convenience in terms of receiving and sending workitems, delegating work to
|
5
|
+
pseudo-participant classes, handling configuration of the communication channel
|
6
|
+
between ruote and the remote participant, and much more.
|
7
|
+
|
8
|
+
== What is ruote?
|
9
|
+
|
10
|
+
Ruote is a Ruby workflow engine. It is a powerful tool for defining, running and
|
11
|
+
orchestrating business processes.
|
12
|
+
|
13
|
+
* http://openwferu.rubyforge.org/
|
14
|
+
* http://www.opensourcery.co.za/2009/03/04/ruote-in-20-minutes/
|
15
|
+
* http://www.opensourcery.co.za/2009/07/06/driving-business-processes-in-ruby/
|
16
|
+
|
17
|
+
== What are remote participants?
|
18
|
+
|
19
|
+
Remote participants are participants that perform their work in a different
|
20
|
+
Ruby processes from the one running the engine. This is useful in two cases,
|
21
|
+
possibily many more, that involves autonomous participants.
|
22
|
+
|
23
|
+
* Autonomous participants located on remote servers, driven by identity
|
24
|
+
* Clustering autonomous participants to process workitems from a queue
|
25
|
+
|
26
|
+
To learn more about the differences between local and remote participants
|
27
|
+
please see http://openwferu.rubyforge.org/part.html
|
28
|
+
|
29
|
+
Currently on the AMQP components are in place in daemon-kit, with XMPP coming
|
30
|
+
soon.
|
31
|
+
|
32
|
+
== Creating a remote participant with daemon-kit
|
33
|
+
|
34
|
+
Generate your daemon using the 'ruote' generator:
|
35
|
+
|
36
|
+
$ daemon_kit partd -i ruote
|
37
|
+
|
38
|
+
Make sure you have the JSON gem install, and the AMQP gem as well.
|
39
|
+
|
40
|
+
== Configuring the daemon
|
41
|
+
|
42
|
+
You need to review +config/ruote.yml+ to specify the AMQP queues that the daemon
|
43
|
+
will subscribe to for receiving workitems. You'll also need to configure the
|
44
|
+
AMQP gem be updating +config/amqp.yml+
|
45
|
+
|
46
|
+
The generated daemon in +libexec/+ already defaults to using AMQP as a transport
|
47
|
+
for workitems.
|
48
|
+
|
49
|
+
== Writing pseudo-participants
|
50
|
+
|
51
|
+
Pseudo-participants in daemon-kit are pure Ruby classes. Implement your classes
|
52
|
+
in +lib/+ and require them from +lib/<daemon_name>.rb+.
|
53
|
+
|
54
|
+
Register your classes as pseudo-participants by registering them in the daemon
|
55
|
+
file in +libexec+, just as the Sample class is registered in the generated
|
56
|
+
code. Your class will be instantiated upon registration, and will be re-used
|
57
|
+
for every incoming workitem passed to it.
|
58
|
+
|
59
|
+
All your public methods in the pseudo-participant classes should be accept
|
60
|
+
a single parameter, which is a ruote workitem in pure Hash form.
|
61
|
+
|
62
|
+
== Wiring up the remote participant in ruote
|
63
|
+
|
64
|
+
See the complete code here: http://gist.github.com/144861
|
65
|
+
|
66
|
+
A sample process definition might look something like this:
|
67
|
+
|
68
|
+
class QuoteProcess < OpenWFE::ProcessDefinition
|
69
|
+
sequence do
|
70
|
+
kit :command => '/sample/quote', :queue => 'work1'
|
71
|
+
|
72
|
+
console
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
+kit+ in the above process definition is registered with the ruote engine as an
|
77
|
+
AMQPParticipant. The AMQPParticipant delivers workitems to the specified AMQP
|
78
|
+
queue.
|
79
|
+
|
80
|
+
Based on the values in +config/ruote.yml+, your daemon will be subscribed to
|
81
|
+
those queues.
|
82
|
+
|
83
|
+
The second part is delegating the workitem inside the daemon to the correct
|
84
|
+
pseudo-participant. This is handled by the +:command+ parameter in the process
|
85
|
+
definition. DaemonKit::Workitem looks at the command parameter of the incoming
|
86
|
+
workitem, and then finds a registered pseudo-participant instance and calls the
|
87
|
+
requested method on that class.
|
88
|
+
|
89
|
+
The +:command+ parameter follows the following convention (stolen shamelessly
|
90
|
+
from Nanite):
|
91
|
+
|
92
|
+
:command => '/class_name/method_name'
|
93
|
+
|
94
|
+
When classes are registered, the name of the class is downcased and camel-case
|
95
|
+
words are separated by underscores. Method names are not changed, but methods
|
96
|
+
are required to be public.
|
97
|
+
|
98
|
+
== Processing workitems and replying to the engine
|
99
|
+
|
100
|
+
The methods called in the pseudo-participants receive a single parameter, a
|
101
|
+
ruote workitem as a hash. The participant is then free to analyze the hash
|
102
|
+
and perform the appropriate actions required. The return value of the method
|
103
|
+
is discarded, and the workitem is returned back to the engine. If the method
|
104
|
+
modified the workitem, these changes will be sent along as well.
|
105
|
+
|
106
|
+
== Random other notes
|
107
|
+
|
108
|
+
Apart from configuring the AMPQ client (or XMPP in future) and the ruote.yml
|
109
|
+
file, daemon developers don't need to worry about anything related to receiving
|
110
|
+
workitems or sending replies.
|
111
|
+
|
112
|
+
Our aim is to allow you to swap between participants on both sides of the
|
113
|
+
transport without changing any of your code.
|
data/TODO.txt
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
= DaemonKit TODO List
|
2
|
+
|
3
|
+
This is purely a drop in the bucket of what has to come...
|
4
|
+
|
5
|
+
== Eye on 0.2
|
6
|
+
|
7
|
+
* Support for dropping privileges
|
8
|
+
* Support for chroot'ing
|
9
|
+
* Altering process names (fully and temporary appending)
|
10
|
+
* bleak_house support
|
11
|
+
* Support for tweaking REE environment variables prior to launch (bash wrapper)
|
12
|
+
* Clustering support (run multiple workers out of same project)
|
13
|
+
* Full 1.9 support in the framework
|
14
|
+
|
15
|
+
== Later
|
16
|
+
|
17
|
+
* [IN PROGRESS] Error handling to the degree Rails does
|
18
|
+
* Easy configuration of an ORM of choice, including patching it if needed (ActiveRecord *cough*)
|
19
|
+
* Improved generators for creating skeleton daemons:
|
20
|
+
* Evented jabber bot
|
21
|
+
* Empty periodic event loop
|
22
|
+
* Empty periodic loop (non-evented)
|
23
|
+
* Queue (SQS, AMQP, etc) pollers
|
24
|
+
* Rake tasks for generating:
|
25
|
+
* Sys-V style init scripts
|
26
|
+
* Plenty of docs, seriously a lot of docs
|
27
|
+
* Specs & features, tons of them too
|
28
|
+
* Integration tests for the specific daemons
|
29
|
+
* Some level of thread safety, or mechanisms to ease thread safety
|
30
|
+
* Built in utilities:
|
31
|
+
* Thread pool for 1.8
|
32
|
+
* Fibre pool for 1.9
|
33
|
+
* Some activesupport-esque functions until activesupport 3.0 hits the streets
|
34
|
+
* DRY up the following:
|
35
|
+
* Loading configuration files for the daemons
|
36
|
+
|
37
|
+
* DON'T FORGET 1.9 SUPPORT
|
@@ -0,0 +1,7 @@
|
|
1
|
+
Description:
|
2
|
+
This generator creates a new skeleton project suitable for easy
|
3
|
+
Ruby daemon development. The generated project is preconfigured
|
4
|
+
and just requires your task specific code.
|
5
|
+
|
6
|
+
Use one of the provided generators to stub out even more
|
7
|
+
functionality for common daemon patterns.
|
@@ -0,0 +1,161 @@
|
|
1
|
+
class DaemonKitGenerator < RubiGen::Base
|
2
|
+
|
3
|
+
DEFAULT_SHEBANG = File.join(Config::CONFIG['bindir'],
|
4
|
+
Config::CONFIG['ruby_install_name'])
|
5
|
+
|
6
|
+
VALID_GENERATORS = ['default', 'jabber', 'cron', 'amqp', 'nanite_agent', 'ruote']
|
7
|
+
|
8
|
+
DEPLOYERS = ['none', 'capistrano']
|
9
|
+
|
10
|
+
default_options :shebang => DEFAULT_SHEBANG, :author => nil
|
11
|
+
|
12
|
+
attr_reader :daemon_name
|
13
|
+
attr_reader :installer
|
14
|
+
attr_reader :deployer
|
15
|
+
attr_reader :cucumber
|
16
|
+
|
17
|
+
def initialize(runtime_args, runtime_options = {})
|
18
|
+
super
|
19
|
+
usage if args.empty?
|
20
|
+
@destination_root = File.expand_path(args.shift)
|
21
|
+
@daemon_name = base_name
|
22
|
+
extract_options
|
23
|
+
end
|
24
|
+
|
25
|
+
def manifest
|
26
|
+
# ensure some sanity
|
27
|
+
unless VALID_GENERATORS.include?( installer )
|
28
|
+
$stderr.puts "Invalid generator: '#{installer}'."
|
29
|
+
$stderr.puts "Valid generators are: #{VALID_GENERATORS.join(', ')}"
|
30
|
+
exit 1
|
31
|
+
end
|
32
|
+
|
33
|
+
unless DEPLOYERS.include?( deployer )
|
34
|
+
$stderr.puts "Invalid deployment mechanism: '#{deployer}'."
|
35
|
+
$stderr.puts "Valid deployers are: #{DEPLOYERS.join(', ')}"
|
36
|
+
exit 1
|
37
|
+
end
|
38
|
+
|
39
|
+
script_options = { :chmod => 0755, :shebang => options[:shebang] == DEFAULT_SHEBANG ? nil : options[:shebang] }
|
40
|
+
|
41
|
+
record do |m|
|
42
|
+
# Ensure appropriate folder(s) exists
|
43
|
+
m.directory ''
|
44
|
+
|
45
|
+
# Create stubs
|
46
|
+
# m.template "template.rb", "some_file_after_erb.rb"
|
47
|
+
# m.template_copy_each ["template.rb", "template2.rb"]
|
48
|
+
# m.file "file", "some_file_copied"
|
49
|
+
# m.file_copy_each ["path/to/file", "path/to/file2"]
|
50
|
+
|
51
|
+
# Readme
|
52
|
+
m.template "README", "README"
|
53
|
+
m.template "Rakefile", "Rakefile"
|
54
|
+
|
55
|
+
# Executable
|
56
|
+
m.directory "bin"
|
57
|
+
m.template "bin/daemon.erb", "bin/#{daemon_name}", script_options
|
58
|
+
|
59
|
+
# Generator
|
60
|
+
if installer == "default"
|
61
|
+
m.directory "libexec"
|
62
|
+
m.template "libexec/daemon.erb", "libexec/#{daemon_name}-daemon.rb"
|
63
|
+
else
|
64
|
+
m.dependency installer, [daemon_name], :destination => destination_root, :collision => :force
|
65
|
+
end
|
66
|
+
|
67
|
+
# Config/Environment
|
68
|
+
m.directory "config"
|
69
|
+
m.file "config/arguments.rb", "config/arguments.rb"
|
70
|
+
m.file "config/boot.rb", "config/boot.rb"
|
71
|
+
m.template "config/environment.rb", "config/environment.rb"
|
72
|
+
m.directory "config/environments"
|
73
|
+
%w{ development test production }.each { |f| m.file "config/environments/#{f}.rb", "config/environments/#{f}.rb" }
|
74
|
+
m.directory "config/pre-daemonize"
|
75
|
+
m.file "config/pre-daemonize/readme", "config/pre-daemonize/readme"
|
76
|
+
m.directory "config/post-daemonize"
|
77
|
+
m.file "config/post-daemonize/readme", "config/post-daemonize/readme"
|
78
|
+
m.directory "script"
|
79
|
+
m.file "script/destroy", "script/destroy", script_options
|
80
|
+
m.file "script/console", "script/console", script_options
|
81
|
+
m.file "script/generate", "script/generate", script_options
|
82
|
+
|
83
|
+
# Libraries
|
84
|
+
m.directory "lib"
|
85
|
+
m.file "lib/daemon.rb", "lib/#{daemon_name}.rb", :collision => :skip
|
86
|
+
|
87
|
+
# Tasks
|
88
|
+
m.directory "tasks"
|
89
|
+
|
90
|
+
# Tests
|
91
|
+
m.dependency "rspec", [daemon_name], :destination => destination_root, :collision => :force
|
92
|
+
if cucumber
|
93
|
+
m.dependency "cucumber", [], :destination => destination_root, :collision => :force
|
94
|
+
end
|
95
|
+
|
96
|
+
# Deployers
|
97
|
+
unless deployer == 'none'
|
98
|
+
m.dependency "deploy_#{deployer}", [daemon_name], :destination => destination_root, :collision => :force
|
99
|
+
end
|
100
|
+
|
101
|
+
# Others
|
102
|
+
m.directory "log"
|
103
|
+
m.directory "tmp"
|
104
|
+
m.directory "vendor"
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
protected
|
109
|
+
def banner
|
110
|
+
<<-EOS
|
111
|
+
Creates a preconfigured environment for writing Ruby daemon processes.
|
112
|
+
|
113
|
+
USAGE: #{spec.name} /path/to/your/daemon [options]
|
114
|
+
EOS
|
115
|
+
end
|
116
|
+
|
117
|
+
def add_options!(opts)
|
118
|
+
opts.separator ''
|
119
|
+
opts.separator 'Options:'
|
120
|
+
# For each option below, place the default
|
121
|
+
# at the top of the file next to "default_options"
|
122
|
+
# opts.on("-a", "--author=\"Your Name\"", String,
|
123
|
+
# "Some comment about this option",
|
124
|
+
# "Default: none") { |o| options[:author] = o }
|
125
|
+
|
126
|
+
opts.on("-i", "--install=generator", String,
|
127
|
+
"Select a generator to use (other than the default).",
|
128
|
+
"Available generators: #{VALID_GENERATORS.join(', ')}",
|
129
|
+
"Defaults to: default") do |installer|
|
130
|
+
options[:installer] = installer
|
131
|
+
end
|
132
|
+
|
133
|
+
opts.on("-d", "--deploy-with=config", String,
|
134
|
+
"Select an optional deployment mechanism.",
|
135
|
+
"Available deployers: #{DEPLOYERS.join(', ')}",
|
136
|
+
"Defaults to: none") do |deploy|
|
137
|
+
options[:deployer] = deploy
|
138
|
+
end
|
139
|
+
|
140
|
+
opts.on("--cucumber",
|
141
|
+
"Install cucumber.") do
|
142
|
+
options[:cucumber] = true
|
143
|
+
end
|
144
|
+
|
145
|
+
opts.on("-r", "--ruby=path", String,
|
146
|
+
"Path to the Ruby binary of your choice (otherwise scripts use env, dispatchers current path).",
|
147
|
+
"Default: #{DEFAULT_SHEBANG}") { |x| options[:shebang] = x }
|
148
|
+
opts.on("-v", "--version", "Show the #{File.basename($0)} version number and quit.")
|
149
|
+
end
|
150
|
+
|
151
|
+
def extract_options
|
152
|
+
# for each option, extract it into a local variable (and create an "attr_reader :author" at the top)
|
153
|
+
# Templates can access these value via the attr_reader-generated methods, but not the
|
154
|
+
# raw instance variable value.
|
155
|
+
# @author = options[:author]
|
156
|
+
@installer = options[:installer] || 'default'
|
157
|
+
@deployer = (options[:deployer] || 'none').strip
|
158
|
+
@cucumber = options[:cucumber] || false
|
159
|
+
end
|
160
|
+
|
161
|
+
end
|