On Fri, Apr 23, 2010 at 7:49 AM, Olle <[email protected]> wrote:
>
> Was "set" intended for setting array elements of process variables?
> Example below tries to set first element of variable 'v1'. It doesn't
> work unlike setting field. Another thing is that setting of process
> variable doesn't parse compound keys.
>
> ---
>  require 'rubygems'
>  require 'ruote'
>  require 'ruote/storage/hash_storage'
>
>
>  engine = Ruote::Engine.new(
>    Ruote::Worker.new(
>      Ruote::HashStorage.new()))
>
>  pdef = Ruote.process_definition :name => 'set test' do
>      echo 'This works: set f:f1.0'
>      set :field => 'f1.0', :value => 'val'
>      echo 'f1[0]: ${f:f1.0}'
>      echo 'This doesn\'t: set v:v1.0'
>      set :var => 'v1.0', :value => 'val'
>      echo 'v1[0]: ${v:v1.0}'
>  end
>
>  wfid = engine.launch  pdef, { 'f1' => [] }, { 'v1' => [] }
>  engine.wait_for(wfid)
> ------

Hello Oleg,

I will investigate/fix that. I think it's good to have the same behaviour for 
process variables and workitem fields.


> Another question is regarding setting process variables inside of
> concurrent expressions. I tried to set variable inside of
> concurrent_iterator, it doesn't work and produce error then run with '-
> d'. If wrap "set" in "sequence" inside of "concurrent_iterator" then
> it just does nothing.
> May be this is a well-known behavior and it's prohibited? I found
> nothing about it in the documentation and tests. So probably it's just
> my inattention.

There are some scoping rules. Mostly subprocesses and concurrent branches get a 
new scope.

This works :

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

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

pdef = Ruote.define do
  concurrent_iterator :on => (1..5).to_a do
    sequence do
      set 'v:v' => '>${v:i}<'
      echo '${v:i} nada ${v:v}'
    end
  end
end

wfid = engine.launch(pdef)

engine.wait_for(wfid)
--->8---

You probably want to do something like

---8<---
pdef = Ruote.define do
  concurrent_iterator :on => (1..5).to_a do
    sequence do
      set 'v:/v' => '>${v:i}<' # <------------------------------ notice the /
      echo '${v:i} nada ${v:v}'
    end
  end
end
--->8---

But then you'll get an output of 

  1 nada >5<
  2 nada >5<
  3 nada >5<
  4 nada >5<
  5 nada >5<

Last 'set' to execute wins.

Try to avoid using process variables in such concurrency cases. Let the merge 
do its work.


> And finally, I have a small suggestion regarding "set" syntax.
> Sometimes it needs to append value to array, without care about
> array's index. It could look like this:
>  set :field => 'array_field.+', :value => 'some_val'
> Maybe you will find this useful.


Could inc/dec be what you need ?

  http://ruote.rubyforge.org/exp/inc.html

Isn't putting too much data manipulation logic in a business process a bit off 
? A participant that does all the complex data manipulation in plain ruby is 
probably better.

What do you think ?


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