Class: Ruote::ProcessObserver

Inherits:
Object
  • Object
show all
Defined in:
lib/ruote/util/process_observer.rb

Overview

A base class for process observers, just to provide convenience. It (heavily) sugar coats the Ruote::Observer and translate the messages into actions. Each such action is provided with pre-distilled information relevant for processes.

Example implementation

require 'ruote/util/process_observer'

class WebsocketSubscriber < Ruote::ProcessObserver
   # override initialize to warm-up a websocket client
   def initialize(context, options={})
     super
     @client = WebsocketClient.new()
   end

   # tell the listeners that a new process launched
   def on_launch(wfid, info)
     @client.publish(
       "/process/launch",
       { :name       => info[:workitem].wf_name,
         :wfid       => wfid,
         :definition => info[:pdef],
       }
     )
   end

   # tell the listeners that a new process ended
   def on_end(wfid)
     @client.publish("/process/#{wfid}", { :end => true })
   end
end

# Bind the observer to the Ruote::Dashboard instance
#
dashboard.add_service('websocket_subscriber', WebsocketSubscriber)

Actions

The ProcessObserver adheres closely to the message actions, it calls the following methods:

on_launch

When a process or sub-process starts

on_terminated

When a process ends

on_error_intercepted

When an error was intercepted

on_cancel

When a process or sub-process was canceled

on_dispatch

When a participant is dispatched

on_receive

Whenever a workitem is received

And others, but if you are interested in those; you might be better of using the more low-level Ruote::Observer

Arguments

The methods are called with (wfid[, info])

You can provide a method-signature like:

def on_launch(wfid, info)
def on_launch(wfid)

ProcessObserver also supports on_pre methods. You can provide a method-signature like:

def on_pre_launch(wfid, info)
def on_pre_launch(wfid)

If the ProcessObserver cannot call the method with the info, it tries to call without info. The info contains a hash of key/value entries.

Info

The following info is provided:

:workitem

The workitem, if available

:action

The original name of the action

:child

Boolean; This is an event of a child, or sub-flow

:error

The intercepted error (only provided with #on_error_intercepted)

:pdef

The (sub-)process definition (only provided with #on_launch)

:variables

The process variables, if available

:flavour

The flavour of canceling (only on_cancel)

Error handling

If anywhere in your implementation an action raises a StandardError, it is caught by the ProcessObserver and silently ignored.

Defined Under Namespace

Classes: Error

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context, options = {}) ⇒ ProcessObserver

Returns a new instance of ProcessObserver


134
135
136
137
138
139
140
141
142
# File 'lib/ruote/util/process_observer.rb', line 134

def initialize(context, options={})

  @filtered_actions = options.delete(:filtered_actions)
  @filtered_actions ||= []
  @filtered_actions |=  %w[dispatched participant_registered variable_set]

  @context = context
  @options = options
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context


132
133
134
# File 'lib/ruote/util/process_observer.rb', line 132

def context
  @context
end

#filtered_actionsObject (readonly)

Returns the value of attribute filtered_actions


132
133
134
# File 'lib/ruote/util/process_observer.rb', line 132

def filtered_actions
  @filtered_actions
end

#optionsObject (readonly)

Returns the value of attribute options


132
133
134
# File 'lib/ruote/util/process_observer.rb', line 132

def options
  @options
end

Instance Method Details

#on_msg(msg) ⇒ Object


149
150
151
152
# File 'lib/ruote/util/process_observer.rb', line 149

def on_msg(msg)

  route(nil, msg)
end

#on_pre_msg(msg) ⇒ Object


144
145
146
147
# File 'lib/ruote/util/process_observer.rb', line 144

def on_pre_msg(msg)

  route('pre', msg)
end