lib/openwfe/expool/yamlexpstorage.rb in openwferu-0.9.16 vs lib/openwfe/expool/yamlexpstorage.rb in openwferu-0.9.17
- old
+ new
@@ -1,8 +1,8 @@
#
#--
-# Copyright (c) 2006-2007, Nicolas Modryzk and John Mettraux, OpenWFE.org
+# Copyright (c) 2006-2008, Nicolas Modryzk and John Mettraux, OpenWFE.org
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
@@ -42,16 +42,17 @@
require 'openwfe/storage/yamlcustom'
require 'openwfe/storage/yamlfilestorage'
require 'openwfe/expool/threadedexpstorage'
require 'openwfe/expressions/flowexpression'
-require 'openwfe/expressions/raw_xml'
- #
+#require 'openwfe/expressions/raw_xml'
+ #--
# making sure classes in those files are loaded
# before their yaml persistence is tuned
# (else the reopening of the class is interpreted as
# a definition of the class...)
+ #++
module OpenWFE
#
@@ -62,63 +63,80 @@
include OwfeServiceLocator
include ExpressionStorageBase
def initialize (service_name, application_context)
- super(service_name, application_context, '/expool')
+ super service_name, application_context, '/expool'
observe_expool
end
#
- # Iterates on each expression that is of the given kind.
- # Used for example by the expression pool when rescheduling.
+ # Find expressions matching various criteria.
+ # (See Engine#list_process_status for an explanation)
#
- def each_of_kind (kind, &block)
+ def find_expressions (options)
- each_object_path do |path|
+ wfid_prefix = options[:wfid_prefix]
+ wfid_regex = nil
+ wfid_regex = Regexp.new("^"+wfid_prefix) if wfid_prefix
- #ldebug { "each_of_kind() path is #{path}" }
+ options.delete :wfid_prefix
+ # no need to check this in further does_match? calls
- #next unless matches(path, kind)
- # was not OK in case of <bob activity="clean office" />
+ result = []
- expression = load_object path
+ each_object_path do |path|
- next unless expression.is_a?(kind)
+ unless path.match /\/engine_environment.yaml$/
+ a = self.class.split_file_path path
+ next unless a
+ # not an expression file
- expression.application_context = @application_context
+ wfid = a[0]
+ next if wfid_regex and (not wfid_regex.match(wfid))
+ end
- block.call expression.fei, expression
+ fexp = load_object path
+
+ next unless does_match?(options, fexp)
+
+ result << fexp
end
+
+ result
end
- #
- # "each flow expression" : this method awaits a block then, for
- # each flow_expression in this storage, calls that block.
- #
- # If wfid_prefix is set, only expressions whose wfid (workflow instance
- # id (process instance id)) will be taken into account.
- #
- def each (wfid_prefix=nil, &block)
+ def fetch_root (wfid)
- each_object_path do |path|
+ fei = FlowExpressionId.new
+ fei.wfid = wfid
+ fei.expid = "0"
+ fei.expression_name = "process-definition"
- a = self.class.split_file_path path
+ root = self[fei]
+
+ return root if root
+
+ #
+ # direct hit missed, scanning...
+
+ each_object_path(compute_dir_path(wfid)) do |p|
+
+ a = self.class.split_file_path p
next unless a
- wfid = a[0]
- next if wfid_prefix and ( ! wfid.match "^#{wfid_prefix}")
+ next unless a[0] == wfid
- flow_expression = load_object path
+ fexp = load_object p
- block.call flow_expression.fei, flow_expression
+ return fexp if fexp.is_a?(DefineExpression)
end
+
+ nil
end
- alias :real_each :each
-
#
# Returns a human-readable list of the current YAML file paths.
# (one expression per path).
#
def to_s
@@ -146,22 +164,27 @@
[ md[1], md[2], md[3] ]
end
protected
+ def compute_dir_path (wfid)
+
+ wfid = FlowExpressionId.to_parent_wfid wfid
+
+ a_wfid = get_wfid_generator.split_wfid wfid
+
+ @basepath + a_wfid[-2] + "/" + a_wfid[-1] + "/"
+ end
+
def compute_file_path (fei)
return @basepath + "/engine_environment.yaml" \
if fei.workflow_instance_id == "0"
wfid = fei.parent_workflow_instance_id
- a_wfid = get_wfid_generator.split_wfid(wfid)
-
- @basepath +
- a_wfid[-2] + "/" +
- a_wfid[-1] + "/" +
+ compute_dir_path(wfid) +
fei.workflow_instance_id + "__" +
fei.expression_id + "_" +
fei.expression_name + ".yaml"
end
@@ -190,10 +213,10 @@
def initialize (service_name, application_context)
super
- start_processing_thread()
+ start_processing_thread
#
# which sets @thread_id
end
end
end