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|
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
ids_to_remove << tracker_id if tracker['msg'].delete('_auto_remove')
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