Parent

Class/Module Index [+]

Quicksearch

Ruote::Workitem

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

The payload/fields MUST be JSONifiable.

Attributes

h[R]

Public Class Methods

from_json(json) click to toggle source

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.

# File lib/ruote/workitem.rb, line 415
def self.from_json(json)

  h = Rufus::Json.decode(json)

  raise ArgumentError(
    "Arg not a JSON hash/object, but a #{h.class}. Cannot create workitem"
  ) unless h.is_a?(Hash)

  self.new(h)
end
new(h) click to toggle source
# File lib/ruote/workitem.rb, line 42
def initialize(h)

  @h = h
  class << @h; include Ruote::HashDot; end

  #class << @h['fields']
  #  alias_method :__get, :[]
  #  alias_method :__set, :[]=
  #  def [](key)
  #    __get(key.to_s)
  #  end
  #  def []=(key, value)
  #    __set(key.to_s, value)
  #  end
  #end
    # indifferent access, not activated for now
end

Public Instance Methods

==(other) click to toggle source

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

# File lib/ruote/workitem.rb, line 193
def ==(other)

  return false if other.class != self.class
  self.h['fei'] == other.h['fei']
end
Also aliased as: eql?
[](key) click to toggle source

Shortcut for lookup(key)

workitem.fields['customer']['city']
  # or
workitem.lookup('customer.city')
  # or
workitem['customer.city']
# File lib/ruote/workitem.rb, line 255
def [](key)

  lookup(key.to_s)
end
[]=(key, value) click to toggle source

Shortcut for set_field(key, value)

workitem.fields['customer']['city'] = 'Toronto'
  # or
workitem.set_field('customer.city', 'Toronto')
  # or
workitem['customer.city'] = 'Toronto'
# File lib/ruote/workitem.rb, line 268
def []=(key, value)

  set_field(key.to_s, value)
end
as_json(pretty=false) click to toggle source

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

# File lib/ruote/workitem.rb, line 407
def as_json(pretty=false)

  pretty ? Rufus::Json.pretty_encode(@h) : Rufus::Json.encode(@h)
end
command() click to toggle source

(advanced)

Shortcut for wi.fields

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

# File lib/ruote/workitem.rb, line 366
def command

  @h['fields']['__command__']
end
command=(com) click to toggle source

(advanced)

Shortcut for wi.fields = x

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

# File lib/ruote/workitem.rb, line 378
def command=(com)

  com = com.is_a?(Array) ? com : com.split(' ')
  com = [ com.first, com.last ]
  com[1] = com[1].to_i if com[1] and com[0] != 'jump'

  @h['fields']['__command__'] = com
end
definition_name() click to toggle source
Alias for: wf_name
definition_revision() click to toggle source
Alias for: wf_revision
dispatched_at() click to toggle source

When was this workitem dispatched ?

# File lib/ruote/workitem.rb, line 186
def dispatched_at

  fields['dispatched_at']
end
dup() click to toggle source

Returns a complete copy of this workitem.

# File lib/ruote/workitem.rb, line 96
def dup

  Workitem.new(Rufus::Json.dup(@h))
end
eql?(other) click to toggle source
Alias for: ==
error() click to toggle source

Shortcut for wi.fields

# File lib/ruote/workitem.rb, line 282
def error

  @h['fields']['__error__']
end
fei() click to toggle source

Returns a Ruote::FlowExpressionId instance.

# File lib/ruote/workitem.rb, line 89
def fei

  FlowExpressionId.new(@h['fei'])
end
field_or_param(key) click to toggle source

Like param_or_field, but priority is given to the field.

# File lib/ruote/workitem.rb, line 344
def field_or_param(key)

  key = key.to_s

  @h['fields'][key] || (@h['fields']['params'] || {})[key]
end
fields() click to toggle source

Returns the payload, ie the fields hash.

# File lib/ruote/workitem.rb, line 151
def fields

  @h['fields']
end
fields=(fields) click to toggle source

Sets all the fields in one sweep.

Remember : the fields must be a JSONifiable hash.

# File lib/ruote/workitem.rb, line 160
def fields=(fields)

  @h['fields'] = fields
end
hash() click to toggle source

Warning : hash is fei’s hash.

# File lib/ruote/workitem.rb, line 203
def hash

  self.h['fei'].hash
end
launched_at() click to toggle source
Alias for: wf_launched_at
lf(key, container_lookup=false) click to toggle source

‘lf’ for ‘lookup field’

Alias for: lookup
lookup(key, container_lookup=false) click to toggle source

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']
# File lib/ruote/workitem.rb, line 224
def lookup(key, container_lookup=false)

  Ruote.lookup(@h['fields'], key, container_lookup)
end
Also aliased as: lf
owner() click to toggle source

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

# File lib/ruote/workitem.rb, line 144
def owner

  @h['owner']
end
param_or_field(key) click to toggle source

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
# File lib/ruote/workitem.rb, line 335
def param_or_field(key)

  key = key.to_s

  (@h['fields']['params'] || {})[key] || @h['fields'][key]
end
param_text() click to toggle source

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.

# File lib/ruote/workitem.rb, line 319
def param_text

  (params.find { |k, v| v.nil? } || []).first
end
params() click to toggle source

Shortcut for wi.fields

When a participant is invoked like in

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

then

p workitem.params
  # => { 'ref' => 'toto', 'task' => 'x' }
# File lib/ruote/workitem.rb, line 298
def params

  @h['fields']['params'] || {}
end
participant_name() click to toggle source

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).

# File lib/ruote/workitem.rb, line 105
def participant_name

  @h['participant_name']
end
re_dispatch_count() click to toggle source

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.

# File lib/ruote/workitem.rb, line 399
def re_dispatch_count

  @h['re_dispatch_count'] || 0
end
result() click to toggle source

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’.

# File lib/ruote/workitem.rb, line 170
def result

  fields['__result__']
end
result=(r) click to toggle source

Sets the value of the ‘special’ field __result__

See result

# File lib/ruote/workitem.rb, line 179
def result=(r)

  fields['__result__'] = r
end
set_field(key, value) click to toggle source

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”.

# File lib/ruote/workitem.rb, line 242
def set_field(key, value)

  Ruote.set(@h['fields'], key, value)
end
sid() click to toggle source

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)
# File lib/ruote/workitem.rb, line 74
def sid

  Ruote::FlowExpressionId.to_storage_id(h.fei)
end
sub_wf_launched_at() click to toggle source

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

# File lib/ruote/workitem.rb, line 139
def sub_wf_launched_at; @h['sub_wf_launched_at']; end
sub_wf_name() click to toggle source

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…)

# File lib/ruote/workitem.rb, line 131
def sub_wf_name; @h['sub_wf_name']; end
sub_wf_revision() click to toggle source

The equivalent of sub_wf_name for revisions.

# File lib/ruote/workitem.rb, line 135
def sub_wf_revision; @h['sub_wf_revision']; end
t() click to toggle source

Shortcut to the temporary/trailing fields

groups.google.com/group/openwferu-users/browse_thread/thread/981dba6204f31ccc

# File lib/ruote/workitem.rb, line 355
def t
  @h['fields']['t'] ||= {}
end
tags() click to toggle source

Shortcut for wi.fields

# File lib/ruote/workitem.rb, line 389
def tags

  @h['fields']['__tags__'] || []
end
timed_out() click to toggle source

Shortcut for wi.fields

# File lib/ruote/workitem.rb, line 275
def timed_out

  @h['fields']['__timed_out__']
end
to_h() click to toggle source

Returns the underlying Hash instance.

# File lib/ruote/workitem.rb, line 62
def to_h

  @h
end
wf_launched_at() click to toggle source

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

# File lib/ruote/workitem.rb, line 121
def wf_launched_at; @h['wf_launched_at']; end
Also aliased as: launched_at
wf_name() click to toggle source

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

# File lib/ruote/workitem.rb, line 112
def wf_name; @h['wf_name']; end
Also aliased as: definition_name
wf_revision() click to toggle source

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

# File lib/ruote/workitem.rb, line 117
def wf_revision; @h['wf_revision']; end
Also aliased as: definition_revision
wfid() click to toggle source

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

# File lib/ruote/workitem.rb, line 82
def wfid

  h.fei['wfid']
end

Protected Instance Methods

add_tag(tag) click to toggle source

Used by FlowExpression when entering a tag.

# File lib/ruote/workitem.rb, line 430
def add_tag(tag)

  (@h['fields']['__tags__'] ||= []) << tag
end
remove_tag(tag) click to toggle source

Used by FlowExpression when leaving a tag.

# File lib/ruote/workitem.rb, line 437
def remove_tag(tag)

  # it's a bit convoluted... trying to cope with potential inconsistencies
  #
  # normally, it should only be a tags.pop(), but since user have
  # access to the workitem and its fields... better be safe than sorry

  tags = (@h['fields']['__tags__'] || [])

  if index = tags.rindex(tag)
    tags.delete_at(index)
  end

  @h['fields']['__left_tag__'] = tag
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.