Created
March 14, 2013 22:46
-
-
Save anonymous/5165918 to your computer and use it in GitHub Desktop.
showcasing ruote error handling participants
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
# Gemfile | |
# | |
# ---8<--- | |
# source :rubygems | |
# | |
# gem 'yajl-ruby', :require => 'yajl' | |
# #gem 'ruote' | |
# gem 'ruote', :git => 'git://github.com/jmettraux/ruote.git' | |
# --->8--- | |
require 'pp' | |
require 'ruote' | |
ruote = | |
Ruote::Dashboard.new( | |
Ruote::Worker.new( | |
Ruote::HashStorage.new)) | |
ruote.noisy = (ENV['NOISY'] == 'true') | |
# | |
# define participant classes (if needed) | |
# | |
class MyParticipant < Ruote::Participant | |
def on_workitem | |
puts "#{self.class} saw workitem for #{workitem.participant_name}" | |
raise 'arghhhhhhhhhhh!' | |
#reply | |
end | |
end | |
class MyErrorHandlerParticipant < Ruote::Participant | |
def on_workitem | |
puts | |
puts '=' * 80 | |
puts 'error:' | |
pp workitem.error | |
puts '=' * 80 | |
rescue => ex | |
puts '*' * 80 | |
p ex | |
puts '*' * 80 | |
end | |
end | |
# | |
# register participants | |
# | |
ruote.register do | |
participant 'alpha', MyParticipant | |
participant 'errory', MyErrorHandlerParticipant | |
end | |
# | |
# define process | |
# | |
pdef = | |
Ruote.define do | |
sequence :on_error => 'errory' do | |
alpha | |
end | |
end | |
# | |
# run process | |
# | |
wfid = ruote.launch(pdef) | |
sleep 3 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment