On Tue, Jul 26, 2011 at 07:00:36PM -0700, Nando Sola wrote: > > After testing your process definition, I'm finding some difficulties > using $children, as it's a global variable shared by all process > instances.
Hello Nando, I'm sorry. The $children global variable I introduced was only "for the example". As you can see in my initial code (https://gist.github.com/1099025), it's set to 4 at first and then decreased until it reaches 0, at which point no more "child" sub branches are created. I only meant this $children variable to simulate a human deciding to launch 4 sub branches and then stop. Please don't use $children, it was only for making my example shorter. > (...) > > The idea behind my proof of concept is that several of these kind of > processes can co-exist without interfering one another. Which brings > me to another doubt: What would be the best way to share a common, > synchronized state between parent and children? Well, I still think that my example "add_branch" process definition would work fine for you. > Unfortunately, stash_* depends too much on the parent's fei, which > changes after each children is added because of the "rewind". So I > think stash_* would be a complicated approach here. > > Maybe a process variable could be set from the participant: > > ---8<--- > class FillParticipant < Ruote::StorageParticipant > def consume(workitem) > children = fexp.lookup_variable('children') > p "in for #{workitem.params['form']} - #{children} children" > workitem.fields['form'] = workitem.params['form'] > workitem.fields['launch'] = false > > super(workitem) > end > > def proceed(workitem) > children = fexp.lookup_variable('children') > if workitem.params['form'] == 'parent' > fexp.set_variable('children', children + 1) if > workitem.fields['launch'] > elsif workitem.params['form'] == 'child' > fexp.set_variable('children', children - 1) > end > > super(workitem) > end > end > --->8--- > > But I get the following error: > > ----- begin ---- > NoMethodError - undefined method `fei' for nil:NilClass: > /Users/nando/development/abstra/blueMountain/Workflow/ruote- > components/ruote/lib/ruote/part/local_participant.rb:77:in `fei' > /Users/nando/development/abstra/blueMountain/Workflow/ruote- > components/ruote/lib/ruote/part/local_participant.rb:88:in `fexp' > /Users/nando/development/abstra/blueMountain/Workflow/participants/ > fill_participant.rb:127:in `proceed' > (...) > ---- end ---- > > It seems that proceed's fexp.lookup_variable falis. OK, I will help you fix this error, though I don't understand why you go after this "children" variable. My FillParticipant is just sample code, I thought you'd replace it with your own business logic in which you don't rely on a "children" variable to determine if children sub forms are necessary... ---8<--- class FillParticipant < Ruote::StorageParticipant def consume(workitem) children = fexp.lookup_variable('children') p "in for #{workitem.params['form']} - #{children} children" workitem.fields['form'] = workitem.params['form'] workitem.fields['launch'] = false super(workitem) end def proceed(workitem) children = fexp(workitem).lookup_variable('children') if workitem.params['form'] == 'parent' fexp(workitem).set_variable('children', children + 1) if workitem.fields['launch'] elsif workitem.params['form'] == 'child' fexp(workitem).set_variable('children', children - 1) end super(workitem) end end --->8--- should work (ruote master branch as of 2011/07/27). The #process method is a bit "out of bound", it doesn't have an implicit workitem like the newest version of #consume (and #on_workitem) have. You have to tell it about the workitem by saying fexp(workitem). But please remember my FillParticipant was only meant to simulate your "if the parent set the field '_launch' to true, then launch a subprocess form". Sorry for the confusion, cheers, -- 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
