public
Description: a ruby workflow engine
Homepage: http://ruote.rubyforge.org
Clone URL: git://github.com/jmettraux/ruote.git
ruote / examples / simple.rb
100644 55 lines (42 sloc) 1.313 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
require 'rubygems'
require 'openwfe/engine' # sudo gem install ruote
 
#
# define a process, just a sequence, from Alice to Bob
 
process_definition = OpenWFE.process_definition :name => 'test' do
  sequence do
    participant 'alice'
    participant 'bob'
  end
end
 
#
# instantiate a ruote engine, the default (transient) one is OK.
# allow it to fetch process definitions from lauchitems.
#
# more info about engines and persistence flavour at
#
# http://openwferu.rubyforge.org/persistence.html
 
engine = OpenWFE::Engine.new(:definition_in_launchitem_allowed => true)
 
#
# register two very basic participants 'alice' and 'bob',
# use a BlockParticipant (simply wrapping some ruby code inside of a
# participant).
#
# more info about participants at
#
# http://openwferu.rubyforge.org/participants.html
 
engine.register_participant 'alice' do |workitem|
  puts '~alice~'
  workitem.fields['message'] = 'hello from Alice !'
end
engine.register_participant 'bob' do |workitem|
  puts '~bob~'
  puts "the message says '#{workitem.fields['message']}'"
end
 
#
# launch the process (let the engine interpret the process definition and
# create a process instance)
 
fei = engine.launch(process_definition)
 
#
# wait for the process instance to terminate before exiting this tiny ruby
# program
 
engine.wait_for(fei)