Skip to content

Instantly share code, notes, and snippets.

@tosch
Created January 16, 2009 08:49
Show Gist options
  • Save tosch/47878 to your computer and use it in GitHub Desktop.
Save tosch/47878 to your computer and use it in GitHub Desktop.
puts "Die Biertester betreten den Raum (Initialisierung der Engine).\n\n"
require 'rubygems'
require 'openwfe/engine' # sudo gem install ruote
#
# start engine (not persistent, all workitems are lost after script execution)
#
engine = OpenWFE::Engine.new(:definition_in_launchitem_allowed => true)
#
# an example process definition
#
process_definition = <<EOT
<process-definition name="beer-test" revision="0.1">
<sequence>
<participant ref="arrival_qa" />
<concurrence>
<participant ref="tester_a" />
<participant ref="tester_b" />
<participant ref="tester_c" />
</concurrence>
<participant ref="chief_tester" />
</sequence>
</process-definition>
EOT
#
# register the first participant
# (We are using the built-in block participant here. This is most useful
# when execution of some Ruby code is necessary.)
#
engine.register_participant :arrival_qa do |workitem|
puts "Ein Bier kommt an. Es ist...\n"
brands = ['Heineken', 'Budweiser', 'Jever', 'Becks', 'Radeberger', 'Sternburg']
# set workitem attribute
workitem.brand = brands[(rand * brands.length)]
puts "...ein #{workitem.brand}!\n\n"
end
OPINIONS = ['super', 'gut', 'gerade noch trinkbar', 'mies', 'ungeniessbar', 'unterirdisch']
#
# register the "normal" tester participants
#
engine.register_participant 'tester_.*' do |workitem|
my_opinion = OPINIONS[(rand * OPINIONS.length)]
# set workitem field
workitem.fields[workitem.participant_name] = my_opinion
# some nice output...
puts "#{workitem.participant_name} findet #{workitem.brand} #{my_opinion}.\n"
end
#
# register the chief tester
#
engine.register_participant :chief_tester do |workitem|
my_opinion = OPINIONS[(rand * OPINIONS.length)]
puts "#{workitem.participant_name} findet #{workitem.brand} #{my_opinion}.\n"
opinion_scores_sum = 2 * OPINIONS.index(my_opinion) # chief tester's
# opinion has more
# value
count = 2
workitem.attributes.each do |k, v|
next unless k.match(/^tester_.*$/)
opinion_scores_sum += OPINIONS.index(v)
count += 1
end
avg_opinion_score = (opinion_scores_sum.to_f / count).round
puts "\nGesamtbewertung: #{workitem.brand} ist #{OPINIONS[avg_opinion_score]}.\n\n"
end
#
# launch the process
#
li = OpenWFE::LaunchItem.new(process_definition)
fei = engine.launch(li)
#
# workflow engines are asynchronous beasts, have to wait for them
# (here we wait for a particular process)
#
engine.wait_for(fei)
puts "Die Bier-Tester verlassen den Raum (Ende des Skripts).\n\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment