Class Ruote::Workitem
In: lib/ruote/workitem.rb
Parent: Object

A workitem can be thought of an "execution token", but with a payload (fields).

The payload/fields MUST be JSONifiable.

Methods

Attributes

h  [R] 

Public Class methods

Given a JSON String, decodes and returns a Ruote::Workitem instance.3 If the decode thing is not an object/hash, will raise an ArgumentError.

Public Instance methods

Warning : equality is based on fei and not on payload !

Shortcut for lookup(key)

  workitem.fields['customer']['city']
    # or
  workitem.lookup('customer.city')
    # or
  workitem['customer.city']

Shortcut for set_field(key, value)

  workitem.fields['customer']['city'] = 'Toronto'
    # or
  workitem.set_field('customer.city', 'Toronto')
    # or
  workitem['customer.city'] = 'Toronto'

Encodes this workitem as JSON. If pretty is set to true, will output prettified JSON.

(advanced)

Shortcut for wi.fields[‘command’]

command is read by the ‘cursor’ and the ‘iterator’ expressions when a workitem reaches it (apply and reply).

(advanced)

Shortcut for wi.fields[‘command’] = x

command is read by the ‘cursor’ and the ‘iterator’ expressions when a workitem reaches it (apply and reply).

definition_name()

Alias for wf_name

definition_revision()

Alias for wf_revision

When was this workitem dispatched ?

Returns a complete copy of this workitem.

eql?(other)

Alias for #==

Shortcut for wi.fields[‘error’]

Returns a Ruote::FlowExpressionId instance.

Like param_or_field, but priority is given to the field.

Returns the payload, ie the fields hash.

Sets all the fields in one sweep.

Remember : the fields must be a JSONifiable hash.

Warning : hash is fei‘s hash.

launched_at()

Alias for wf_launched_at

lf(key, container_lookup=false)

Alias for lookup

For a simple key

  workitem.lookup('toto')

is equivalent to

  workitem.fields['toto']

but for a complex key

  workitem.lookup('toto.address')

is equivalent to

  workitem.fields['toto']['address']

Used by some participants, returns the "owner" of the workitem. Mostly used when reserving workitems.

Sometimes a value is passed as a[n expression] parameter or as a workitem field, with priority to the parameter.

  sequence do
    set 'f:country' => 'uruguay'
    participant 'toto'
      # in toto, workitem.param_or_field(:country) will yield 'uruguay'
    participant 'toto', :country => 'argentina'
      # workitem.param_or_field(:country) will yield 'argentina'
  end

When a participant is invoked like in

   accounting 'do_invoice', :customer => 'acme corp'

then

   p workitem.params
     # => { 'ref' => 'accounting', 'do_invoice' => nil, 'customer' => 'acme corp' }

and

   p workitem.param_text
     # => 'do_invoice'

It returns nil when there is no text passed directly.

Shortcut for wi.fields[‘params’]

When a participant is invoked like in

   participant :ref => 'toto', :task => 'x"

then

   p workitem.params
     # => { 'ref' => 'toto', 'task' => 'x' }

The participant for which this item is destined. Will be nil when the workitem is transiting inside of its process instance (as opposed to when it‘s being delivered outside of the engine).

How many times was this workitem re_dispatched ?

It‘s used by LocalParticipant re_dispatch mostly, or by participant which poll a resource and re_dispatch after a while.

A shortcut to the value in the field named result

This field is used by the if expression for instance to determine if it should branch to its ‘then’ or its ‘else’.

Sets the value of the ‘special’ field result

See result

Like lookup allows for nested lookups, set_field can be used to set sub fields directly.

  workitem.set_field('customer.address.city', 'Pleasantville')

Warning : if the customer and address field and subfield are not present or are not hashes, set_field will simply create a "customer.address.city" field and set its value to "Pleasantville".

Returns the String id for this workitem (something like "0_0!!20100507-wagamama").

It‘s in fact a shortcut for

  Ruote::FlowExpressionId.to_storage_id(h.fei)

Returns the UTC time string indicating when the sub-workflow was launched.

Returns the name of the sub-workflow the workitem is currently in. (If it‘s in the main flow, it will return the name of the main flow, if that flow has a name…)

The equivalent of sub_wf_name for revisions.

Shortcut for wi.fields[‘tags’]

Shortcut for wi.fields[‘timed_out’]

Returns the underlying Hash instance.

Returns the UTC time string indicating when the workflow was launched.

Returns the name of the workflow to which this workitem belongs, or nil.

Returns the revision of the workflow to which this workitem belongs, or nil.

Returns the "workflow instance id" (unique process instance id) of the process instance which issued this workitem.

Protected Instance methods

Used by FlowExpression when entering a tag.

Used by FlowExpression when leaving a tag.

[Validate]