On Fri, Apr 01, 2011 at 11:42:50AM -0700, catalina cordoba wrote:
> 
> I'm trying to create a process in ruote and I want to save workitems
> in a concurrent way. I want to know, what kind of storage should I
> use.

Hello,

welcome to the ruote mailing list.

You can use any storage. Perhaps the Ruote::HashStorage will not be your 
favourite because it only stores "in memory".

> Specifically I want to save HTTP get responses in a concurrent
> way (With the concurrence expression) in my process. If I could have
> some example, it will be perfect,

It's a bit crude and naive but here is your example :

(https://gist.github.com/898813)

---8<---
require 'rubygems'
require 'json'
require 'ruote'
require 'ruote/storage/fs_storage'
require 'open-uri'

engine = Ruote::Engine.new(
  Ruote::Worker.new(
    Ruote::FsStorage.new('ruote_work')))

engine.noisy = true

pdef = Ruote.process_definition do
  concurrence :merge_type => :isolate do
    get :uri => 
'http://www.google.com/search?ie=UTF-8&oe=UTF-8&sourceid=navclient&q=catalina+cordoba'
    get :uri => 'http://en.wikipedia.org/wiki/Joseph_conrad'
  end
  summarize
end

class Getter
  include Ruote::LocalParticipant

  def consume(workitem)
    uri = workitem.params['uri']
    workitem.fields['got'] = [ uri, open(uri).read ]
    reply(workitem)
  end
end

class Summarize
  include Ruote::LocalParticipant

  def consume(workitem)
    %w[ 0 1 ].each do |key|
      uri, body = workitem.fields[key]['got']
      puts " * #{uri} : #{body.size} chars"
    end
    reply(workitem)
  end
end

engine.register_participant :get, Getter
engine.register_participant :summarize, Summarize

wfid = engine.launch(pdef)
engine.wait_for(wfid)
--->8---

It's not a good idea to store documents inside of a workitem. It would be 
better to save the GET request results into files and to keep only the path of 
the files in the workitem, but it's late here and I wanted a straightforward 
example. I trust you to make it smarter.


Best regards,

-- 
John Mettraux - http://jmettraux.wordpress.com

-- 
you received this message because you are subscribed to the "ruote users" group.
to post : send email to [email protected]
to unsubscribe : send email to [email protected]
more options : http://groups.google.com/group/openwferu-users?hl=en

Reply via email to