lib/openwfe/expool/errorjournal.rb in openwferu-0.9.13 vs lib/openwfe/expool/errorjournal.rb in openwferu-0.9.14

- old
+ new

@@ -78,14 +78,19 @@ # # The String stack trace of the error. # attr_reader :stacktrace + # + # The error class (String) of the top level error + # + attr_reader :error_class + def initialize (*args) @date = Time.new - @fei, @message, @workitem, @stacktrace = args + @fei, @message, @workitem, @error_class, @stacktrace = args end # # Returns the parent workflow instance id (process id) of this # ProcessError instance. @@ -101,17 +106,38 @@ # ProcessError instance. # def to_s s = "" s << "-- #{self.class.name} --\n" - s << " date : #{@date}\n" - s << " fei : #{@fei}\n" - s << " message : #{@message}\n" - s << " workitem : ...\n" - s << " stacktrace : #{@stacktrace[0, 80]}\n" + s << " date : #{@date}\n" + s << " fei : #{@fei}\n" + s << " message : #{@message}\n" + s << " workitem : ...\n" + s << " error_class : #{@error_class}\n" + s << " stacktrace : #{@stacktrace[0, 80]}\n" s end + + # + # Returns a hash + # + def hash + to_s.hash + # + # a bit costly but as it's only used by resume_process()... + end + + # + # Returns true if the other instance is a ProcessError and is the + # same error as this one. + # + def == (other) + return false unless other.is_a?(ProcessError) + return to_s == other.to_s + # + # a bit costly but as it's only used by resume_process()... + end end # # This is a base class for all error journal, don't instantiate, # work rather with InMemoryErrorJournal (only for testing envs though), @@ -127,11 +153,17 @@ get_expression_pool.add_observer(:error) do |event, *args| # # logs each error occuring in the expression pool - record_error(ProcessError.new(*args)) + begin + + record_error(ProcessError.new(*args)) + + rescue Exception => e + lwarn { "*** process error : \n" + args.join("\n") } + end end end # # Returns true if the given wfid (or fei) (process instance id) @@ -240,10 +272,22 @@ wfid = to_wfid(wfid) @per_processes.delete(wfid) end # + # Removes a list of errors from the error journal. + # + def remove_errors (wfid, errors) + + log = get_error_log wfid + + errors.each do |e| + log.delete e + end + end + + # # Reads all the error logs currently stored. # Returns a hash wfid --> error list. # def get_error_logs @@ -328,9 +372,41 @@ # a FlowExpressionId instance. # def remove_error_log (wfid) File.delete(get_path(wfid)) + end + + # + # Removes a list of errors from this error journal. + # + def remove_errors (wfid, errors) + + # load all errors + + log = get_error_log wfid + + # remove the given errors + + errors.each do |e| + log.delete e + end + + # rewrite error file + + path = get_path wfid + + if log.size > 0 + + File.open(path, "w") do |f| + log.each do |e| + f.puts e.to_yaml + end + end + else + + File.delete path + end end # # Reads all the error logs currently stored. # Returns a hash wfid --> error list.