def on_message(pre, message)

      m_wfid = message['wfid'] || (message['fei']['wfid'] rescue nil)
      m_error = message['error']

      m_action = message['action']
      m_action = "pre_#{m_action}" if pre

      msg = m_action == 'error_intercepted' ? message['msg'] : message

      ids_to_remove = []

      trackers.each do |tracker_id, tracker|

        # filter msgs

        t_wfid = tracker['wfid']
        t_action = tracker['action']

        next if t_wfid && t_wfid != m_wfid
        next if t_action && t_action != m_action

        next unless does_match?(message, tracker['conditions'])

        if tracker_id == 'on_error' || tracker_id == 'on_terminate'

          fs = msg['workitem']['fields']

          next if m_action == 'error_intercepted' && fs['__error__']
          next if m_action == 'terminated' && (fs['__error__'] || fs['__terminate__'])
        end

        # remove the message post-trigger?

        ids_to_remove << tracker_id if tracker['msg'].delete('_auto_remove')

        # OK, have to pull the trigger (or alter the message) then

        if pre && tracker['msg']['_alter']
          alter(m_wfid, m_error, m_action, msg, tracker)
        else
          trigger(m_wfid, m_error, m_action, msg, tracker)
        end
      end

      remove(ids_to_remove, nil)
    end
def on_message(pre, message)

      m_wfid = message['wfid'] || (message['fei']['wfid'] rescue nil)
      m_error = message['error']

      m_action = message['action']
      m_action = "pre_#{m_action}" if pre

      msg = m_action == 'error_intercepted' ? message['msg'] : message

      ids_to_remove = []

      trackers.each do |tracker_id, tracker|

        # filter msgs

        t_wfid = tracker['wfid']
        t_action = tracker['action']

        next if t_wfid && t_wfid != m_wfid
        next if t_action && t_action != m_action

        next unless does_match?(message, tracker['conditions'])

        if tracker_id == 'on_error' || tracker_id == 'on_terminate'

          fs = msg['workitem']['fields']

          next if m_action == 'error_intercepted' && fs['__error__']
          next if m_action == 'terminated' && (fs['__error__'] || fs['__terminate__'])
        end

        # remove the message post-trigger?

        ids_to_remove << tracker_id if tracker['msg'].delete('_auto_remove')

        # OK, have to pull the trigger (or alter the message) then

        if pre && tracker['msg']['_alter']
          alter(m_wfid, m_error, m_action, msg, tracker)
        else
          trigger(m_wfid, m_error, m_action, msg, tracker)
        end
      end

      remove(ids_to_remove, nil)
    end
The method behind on_pre_msg and on_msg. Filters msgs against trackers.
 Triggers trackers if there is a match.