Skip to content

Instantly share code, notes, and snippets.

@jmettraux
Created October 4, 2011 01:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmettraux/1260723 to your computer and use it in GitHub Desktop.
Save jmettraux/1260723 to your computer and use it in GitHub Desktop.
require 'rexml/document'
require 'pp'
require 'rubygems'
require 'ruote'
engine = Ruote::Engine.new(Ruote::Worker.new(Ruote::HashStorage.new()))
class FetchData
include Ruote::LocalParticipant
def consume(workitem)
workitem.fields['xml'] = %{
<?xml version='1.0?>
<car color="blue"><constructor name="nissan"/></car>
}.strip
reply_to_engine(workitem)
end
def cancel(fei, flavour)
# nothing to do
end
end
class ProcessData
include Ruote::LocalParticipant
def consume(workitem)
xml = REXML::Document.new(workitem.fields['xml'])
constructor = REXML::XPath.first(xml, '//constructor')
workitem.fields['constructor'] = constructor.attribute('name').value
pp workitem.fields
reply_to_engine(workitem)
end
def cancel(fei, flavour)
# nothing to do
end
end
engine.register 'fetch_data', FetchData
engine.register 'process_data', ProcessData
pdef = Ruote.define do
fetch_data
process_data
end
engine.noisy = true
wfid = engine.launch(pdef)
r = engine.wait_for(wfid)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment