lib/openwfe/expool/journal_replay.rb in openwferu-0.9.10.653 vs lib/openwfe/expool/journal_replay.rb in openwferu-0.9.11
- old
+ new
@@ -134,10 +134,64 @@
def decompose (file_path)
do_decompose(load_events(file_path), [], nil, 0)
end
+ #
+ # Loads a journal file and return the content as a list of
+ # events. This method is made available for unit tests, as
+ # a public method it has not much interest.
+ #
+ def load_events (file_path)
+
+ File.open(file_path) do |f|
+ s = YAML.load_stream f
+ s.documents
+ end
+ end
+
+ #
+ # Takes an error event (as stored in the journal) and replays it
+ # (usually you'd have to fix the engine conf before replaying
+ # the error trigger)
+ #
+ # (Make sure to fix the cause of the error before triggering this
+ # method)
+ #
+ def replay_at_error (error_source_event)
+
+ get_expression_pool.queue_work \
+ error_source_event[3], # message (:do_apply for example)
+ error_source_event[2], # fei or exp
+ error_source_event[4] # workitem
+
+ # 0 is :error and 1 is the date and time of the error
+
+ linfo do
+ fei = extract_fei(error_source_event[2])
+ "replay_at_error() #{error_source_event[3]} #{fei}"
+ end
+ end
+
+ #
+ # Detects the last error that ocurred for a workflow instance
+ # and replays at that point (see replay_at_error).
+ #
+ # (Make sure to fix the cause of the error before triggering this
+ # method)
+ #
+ def replay_at_last_error (wfid)
+
+ events = load_events(get_path(wfid))
+
+ error_event = events.reverse.find do |evt|
+ evt[0] == :error
+ end
+
+ replay_at_error(error_event)
+ end
+
protected
def do_decompose (events, result, previous_state, offset)
current_state = extract_state(events, offset)
@@ -147,18 +201,10 @@
result << current_state
do_decompose(events, result, current_state, offset + 1)
end
- def load_events (file_path)
-
- File.open(file_path) do |f|
- s = YAML.load_stream f
- s.documents
- end
- end
-
def extract_state (file, offset)
events = if file.is_a?(String)
load_events(file)
else
@@ -187,10 +233,11 @@
fei = e[2]
next if etype == :apply
next if etype == :reply
next if etype == :reply_to_parent
+ next if etype == :error
next if seen[fei]
seen[fei] = true
next if etype == :remove
@@ -206,9 +253,10 @@
events.reverse.each do |e|
etype = e[0]
fei = extract_fei e[2]
next if etype == :update
next if etype == :remove
+ next if etype == :error
#next if etype == :reply_to_parent
next if seen[fei]
next unless participants[fei]
seen[fei] = true
dynamic << e