Class: Ruote::Observer

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

Overview

An abstract class for observing the activity of a ruote engine.

Subclass it and add it as a service to observe certain events.

require 'ruote/observer'

class MyLaunchObserver < Ruote::Observer

  def on_pre_msg_launch(msg)
    puts "about to launch process instance #{msg['wfid']}"
  end

  def on_msg_launch(msg)
    puts "just launched process instance #{msg['wfid']}"
  end
end

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

# ...

Simply add a “on_pre_msg_<msg_name>” or “on_msg_<msg_name>” method for it to intercept the given messages.

See Ruote::ProcessObserver for a base class with precisely defined methods with helpful arguments if you don't want to investigate “msgs” too much.

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ Observer

Returns a new instance of Observer


61
62
63
64
# File 'lib/ruote/observer.rb', line 61

def initialize(context)

  @context = context
end

Instance Method Details

#on_msg(msg) ⇒ Object


71
72
73
74
# File 'lib/ruote/observer.rb', line 71

def on_msg(msg)

  route(nil, msg)
end

#on_pre_msg(msg) ⇒ Object


66
67
68
69
# File 'lib/ruote/observer.rb', line 66

def on_pre_msg(msg)

  route('pre', msg)
end