lib/openwfe/engine/status_methods.rb in ruote-0.9.19 vs lib/openwfe/engine/status_methods.rb in ruote-0.9.20

- old
+ new

@@ -1,43 +1,29 @@ -# #-- -# Copyright (c) 2007-2008, John Mettraux, OpenWFE.org -# All rights reserved. +# Copyright (c) 2007-2009, John Mettraux, jmettraux@gmail.com # -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: # -# . Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. # -# . Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. # -# . Neither the name of the "OpenWFE" nor the names of its contributors may be -# used to endorse or promote products derived from this software without -# specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. +# Made in Japan. #++ -# -# -# "made in Japan" -# -# John Mettraux at openwfe.org -# module OpenWFE # # ProcessStatus represents information about the status of a workflow @@ -66,10 +52,17 @@ # The list of all the expressions in the process (active or not). # attr_reader :all_expressions # + # A list of all the applied workitems found in the process + # (participant expressions, for example, do keep a copy of the workitem + # they dispatched to the actual participant. + # + attr_reader :applied_workitems + + # # A hash whose values are ProcessError instances, the keys # are FlowExpressionId instances (fei) (identifying the expressions # that are concerned with the error) # attr_reader :errors @@ -107,10 +100,11 @@ def initialize @wfid = nil @expressions = nil @all_expressions = [] + @applied_workitems = [] @errors = {} @launch_time = nil @variables = nil @scheduled_jobs = nil @paused = false @@ -148,10 +142,19 @@ @expressions.size end # + # Returns a list of the expression ids of the workitem currently active + # for this process + # + def workitem_expids + + @expressions.collect { |exp| exp.fei.expid } + end + + # # Returns the tags currently set in this process. # def tags return [] unless @variables @@ -169,100 +172,101 @@ #@expressions.first.paused? @paused end # + # Returns the tree (representation of the process definition) as it + # currently is (in-flight modifications taken into account). + # + def current_tree + + #@all_expressions.representation + @all_expressions.tree + end + + # + # Returns the tree (representation of the process definition) as it + # was when the process instance was launched (in-flight modifications + # are NOT taken into account). + # + def initial_tree + + #@all_expressions.find_root_expression.raw_representation + @all_expressions.initial_tree + end + + # # this method is used by Engine.get_process_status() when # it prepares its results. # def << (item) if item.is_a?(FlowExpression) - @wfid ||= item.fei.parent_wfid + fei = item.fei - @variables = item.variables \ - if item.is_a?(Environment) and item.fei.expid == "0" + @wfid ||= fei.parent_wfid + @variables = item.variables if ( + item.is_a?(Environment) and + fei.sub_instance_id == '' and + fei.expid == '0') + @launch_time ||= item.apply_time \ if item.fei.expid == '0' and item.fei.is_in_parent_process? @all_expressions << item + wi = nil + wi = item.applied_workitem if item.respond_to?(:applied_workitem) + @applied_workitems << wi if wi + else @errors[item.fei] = item end end + #-- + # A lighter version + # + #def to_h + #end + # + # moved to lib/openwfe/representations.rb + #++ + protected # # Prepares the @expressions instance variable. This method # is only called by the process_status method of the Engine. # def pack_expressions @expressions = [] - @all_expressions.sort_by { |fe| fe.fei.expid }.each do |fe| + @all_expressions.sort_by { |fe| + "#{fe.fei.wfid} #{fe.fei.expid}" + }.each do |fe| next unless fe.apply_time - # no Environment or RawExpression instances + # no Environment instances allowed @expressions.delete_if { |e| e.fei == fe.parent_id } @expressions << fe end end end # - # just a nice to_s for the ProcessStatuses hash + # Simply adding a timestamp # module StatusesMixin attr_accessor :timestamp - - # - # Renders a nice, terminal oriented, representation of an - # Engine.get_process_status() result. - # - # You usually directly benefit from this when doing - # - # puts engine.get_process_status.to_s - # - def to_s - - # TODO : include launch_time and why is process_id so long ? - - s = "" - s << "process_id | name | rev | brn | err | paused? \n" - s << "--------------------+-------------------+---------+-----+-----+---------\n" - - self.keys.sort.each do |wfid| - - status = self[wfid] - fexp = status.expressions.first - ffei = fexp.fei - - s << "%-19s" % wfid[0, 19] - s << " | " - s << "%-17s" % ffei.workflow_definition_name[0, 17] - s << " | " - s << "%-7s" % ffei.workflow_definition_revision[0, 7] - s << " | " - s << "%3s" % status.expressions.size.to_s[0, 3] - s << " | " - s << "%3s" % status.errors.size.to_s[0, 3] - s << " | " - s << "%5s" % status.paused?.to_s - s << "\n" - end - - s - end end # # This mixin is only included by the Engine class. It contains all # the methods about ProcessStatus. @@ -297,61 +301,61 @@ # for a year (:wfid_prefix => '2007'), a month (:wfid_prefix => '200705') or # a day (:wfid_prefix => '20070529'). # def process_statuses (options={}) - return @all_status_cache if options == {} and @all_status_cache + all = (options == {}) + return @all_status_cache if all and @all_status_cache + init_status_cache unless @status_cache options = { :wfid_prefix => options } if options.is_a?(String) expressions = get_expression_storage.find_expressions(options) result = expressions.inject({}) do |r, fe| - - #next unless (fe.apply_time or fe.is_a?(Environment)) - #next if fe.fei.wfid == '0' # skip the engine env - - (r[fe.fei.parent_wfid] ||= ProcessStatus.new) << fe - r + (r[fe.fei.parent_wfid] ||= ProcessStatus.new) << fe; r end result.values.each do |ps| ps.paused = (get_expool.paused_instances[ps.wfid] != nil) get_error_journal.get_error_log(ps.wfid).each { |er| ps << er } - ps.send :pack_expressions # letting it protected + ps.send(:pack_expressions) # letting it protected ps.scheduled_jobs = get_scheduler.find_jobs(ps.wfid) - - if ps.expressions.size == 0 - # drop result if there are no expressions - result.delete(ps.wfid) - @status_cache.delete(ps.wfid) - else - @status_cache[ps.wfid] = ps - end end + result.delete('0') + @status_cache.delete('0') + # # done result.extend(StatusesMixin) result.timestamp = Time.now - @all_status_cache = result - # cache and return + @all_status_cache = result if all + + result end - # # list_process_status() will be deprecated at release 1.0.0 + #alias :list_process_status :process_statuses + # - alias :list_process_status :process_statuses + # Like process_statuses, but returns an Array (of ProcessStatus instances) + # instead of a Hash. + # + def processes (options={}) + process_statuses(options).values + end + # # Returns the process status of one given process instance. # def process_status (wfid) @@ -359,10 +363,11 @@ (r = @status_cache[wfid]) and return r wfid = extract_wfid(wfid, true) - process_statuses(:wfid_prefix => wfid).values.first + #process_statuses(:wfid_prefix => wfid).values.first + process_statuses(:wfid => wfid).values.first end # # Returns true if the process is in pause. #