Skip to content

Instantly share code, notes, and snippets.

Created September 24, 2010 09:41
Show Gist options
  • Save anonymous/595132 to your computer and use it in GitHub Desktop.
Save anonymous/595132 to your computer and use it in GitHub Desktop.
$:.unshift('lib') # running from ruote/ probably
require 'fileutils'
require 'rubygems'
require 'ruote'
require 'ruote/storage/fs_storage'
# preparing the engine
engine = Ruote::Engine.new(
Ruote::Worker.new(
Ruote::FsStorage.new(
'ruote_work',
's_logger' => [ 'ruote/log/test_logger', 'Ruote::TestLogger' ])))
# registering participants
engine.register_participant :alpha do |workitem|
workitem.fields['message'] = { 'text' => 'hello !', 'author' => 'Alice' }
end
engine.register_participant :bravo do |workitem|
puts "I received a message from #{workitem.fields['message']['author']}"
end
# defining a process
pdef = Ruote.process_definition :name => 'test' do
sequence do
participant :alpha
wait '5s'
participant :bravo
end
end
# launching, creating a process instance
WFID_FILE = 'ruote_quickstart_wfid.txt'
wfid = File.read(WFID_FILE).strip rescue nil
wfid ||= engine.launch(pdef)
File.open(WFID_FILE, 'wb') { |f| f.write(wfid) }
engine.wait_for(wfid)
# blocks current thread until our process instance terminates
FileUtils.rm(WFID_FILE)
# => 'I received a message from Alice'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment