Process definitions in Ruby

Ruote (OpenWFEru) understands process definitions expressed as XML documents. The language is not BPEL nor XPDL, hence it’s not the product of a comittee but it has evolved since 2001 to satisfy the needs of a varied community of people.

With the move to Ruby, it became clear that the same constructs expressed via XML could be formulated via the Ruby language itself. Thus

  <process-definition name="myBusinessProcess" revision="0.1">
    <sequence>
      <participant ref="alice" />
      <participant ref="bob" />
    </sequence>
  </process-definition>

is understood by Rufus as well as

  class MyBusinessProcess02 < OpenWFE::ProcessDefinition
    sequence do
      participant :ref => 'alice'
      participant :ref => 'bob'
    end
  end

After all, there are process definitions that are interpreted to give process instances, it parallels classes interpreted to give object / instances.

Note that this can be shortened to :

  class MyBusinessProcess03 < OpenWFE::ProcessDefinition
    sequence do
      participant 'alice'
      participant 'bob'
    end
  end

One step further :

  class MyBusinessProcess04 < OpenWFE::ProcessDefinition
    sequence do
      alice
      bob
    end
  end

This latter step being equivalent to :

  <process-definition name="myBusinessProcess" revision="0.5">
    <sequence>
      <alice />
      <bob />
    </sequence>
  </process-definition>

As Ruote will automatically try to extrapolate ‘unknown expressions’ (here ‘alice’ and ‘bob’) into participant or sub-processes.

escaping ‘if’ and ‘break’

Expression names that match ruby keywords can be escaped by prepending an underscore ‘_’ to them :

  class OtherBusinessProcess01 < OpenWFE::ProcessDefinition
    sequence do
      _if :test => "${f:customer} == 'dupont'" do
        subprocess :ref => 'vip_customer_process'
        subprocess :ref => 'plain_customer_process'
      end
      participant :ref => 'accounting' :activity => 'charge customer'
    end
  end

If you use ‘if’ (no underscore prefix), the process definition will be broken.

ruby as a macro language in the process definition

In a Ruby process definition, it’s perfectly OK to use Ruby as a ‘macro language’

  class YourBusinessProcess01 < OpenWFE::ProcessDefinition
    sequence do
      %w{ alpha bravo charly doug }.each do |pn|
        participant :ref => pn
      end
    end
  end

This is equivalent to

  class YourBusinessProcess01 < OpenWFE::ProcessDefinition
    sequence do
      participant :ref => alpha
      participant :ref => bravo
      participant :ref => charly
      participant :ref => doug
    end
  end

It’s maybe a bit hard to track, but it works.

ruby process definition generators

(later)