Created
July 10, 2009 22:19
-
-
Save kennethkalmer/144861 to your computer and use it in GitHub Desktop.
Example for using ruote & daemon-kit together
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Requirements: | |
# * ruote-2.1.10 or later | |
# * ruote-amqp-2.1.10 or later | |
# * daemon-kit-0.1.8rc3 or later | |
# | |
require 'rubygems' | |
require 'ruote' | |
require 'ruote/storage/fs_storage' | |
require 'ruote-amqp' | |
AMQP.settings[:host] = 'localhost' | |
AMQP.settings[:user] = 'ruote' | |
AMQP.settings[:pass] = 'ruote' | |
AMQP.settings[:vhost] = 'ruote-test' | |
engine = Ruote::Engine.new( | |
Ruote::Worker.new( | |
Ruote::FsStorage.new('work') | |
) | |
) | |
quote_process = Ruote.process_definition :name => 'Quote Process' do | |
sequence do | |
kit :command => '/sample/quote', :queue => 'work1' | |
print_quote | |
end | |
end | |
error_process = Ruote.process_definition :name => 'Error Process' do | |
sequence do | |
kit :command => '/sample/err', :queue => 'work1' | |
print_err | |
end | |
end | |
engine.register_participant( 'kit', RuoteAMQP::Participant ) | |
RuoteAMQP::WorkitemListener.new( engine ) | |
engine.register_participant( 'print_quote' ) do |workitem| | |
p [ :quote, workitem.lookup('quote') ] | |
end | |
engine.register_participant( 'print_err' ) do |workitem| | |
p [ :error, workitem.error ] | |
end | |
puts "Launching QuoteProcess" | |
fei = engine.launch( quote_process ) | |
engine.wait_for( fei ) | |
3.times { puts "" } | |
puts "Launching ErrorProcess" | |
fei = engine.launch( error_process ) | |
engine.wait_for( fei ) | |
3.times { puts "" } | |
puts "Errors in engine" | |
puts engine.errors.inspect |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment