On Thu, Jan 13, 2011 at 07:20:15PM +0100, Gonzalo Suárez wrote:
> 
> I would like to give the storage_participant some notification
> behavior (with xmpp).
>
> (...)
> 
> Then I thought that I could modify the original storage_participant to
> receive a flag (:xmpp => true). If a participant is registered as
> storage_participant with xmpp flag then after consume(), reply(),
> cancel()... methods, some xmpp task would be fired up?
> 
> Does this sound kind of reasonable?
> 
> The thing is that I can't get to know how to pass options to the
> storage_participant and grab them in the initialize() method.

Hello Gonzalo,

I cooked up an example for you, but at first I had to make the 
StorageParticipant options available as a instance variable :

  
https://github.com/jmettraux/ruote/commit/1137fcd848aa7bee8234246518f2a396aaf9818a

> Here is
> the code for registration in RuoteKit:
> 
> RuoteKit.engine.participant_list = [
>   [ 'form', 'Ruote::StorageParticipant', { :xmpp => true } ]
> ]
> 
> I thought that I could insert some options inside the empty hash but I
> don't know if that is reserved for some kind of context stuff... Am I
> doing something wrong?

It is right. Just that since everything in a storage is written as JSON, 
symbols do not survive as such, they're turned into strings.

Here is the example :

---8<---
require 'rubygems'
require 'ruote'

engine = Ruote::Engine.new(Ruote::Worker.new(Ruote::HashStorage.new))

class GonzaloParticipant < Ruote::StorageParticipant
  def consume(workitem)
    puts "XMPP: consuming wi for #{workitem.fei.sid}" if @options['xmpp']
    super
  end
  def cancel(fei, flavour)
    puts "XMPP: cancelling wi at #{fei.sid}" if @options['xmpp']
    super
  end
end

engine.register do
  form GonzaloParticipant, :xmpp => true
  #bob GonzaloParticipant
end
  # or
#engine.participant_list = [
#  [ 'form', 'GonzaloParticipant', { 'xmpp' => 'true' } ]
#]
  # note that symbols are turned into strings when stored,
  # it's a JSON world

pdef = Ruote.process_definition do
  form
end

engine.noisy = true
  # displaying the worker's work, step by step, in yellow

wfid = engine.launch(pdef)

engine.wait_for(:form)

puts
puts "workitem received by 'form' : "
puts
p engine.storage_participant.first
--->8---

Its gist is at :

  https://gist.github.com/778934


I hope this will help, 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