lib/openwfe/expool/yamlexpstorage.rb in openwferu-0.9.2 vs lib/openwfe/expool/yamlexpstorage.rb in openwferu-0.9.3

- old
+ new

@@ -38,12 +38,14 @@ # # Nicolas Modrzyk at openwfe.org # John Mettraux at openwfe.org # -require 'find' +#require 'find' +require 'openwfe/utils' +require 'openwfe/rudefinitions' require 'openwfe/storage/yamlfilestorage' require 'openwfe/expressions/flowexpression' require 'openwfe/expressions/raw_xml' # @@ -82,46 +84,80 @@ # # yaml expression storage # class YamlFileExpressionStorage < YamlFileStorage + include OwfeServiceLocator def initialize (service_name, application_context) path = if (@application_context) @application_context[:file_expression_storage_path] else DEFAULT_FILE_STORAGE_PATH end super(service_name, application_context, path + "/expool") end - - def compute_file_path (fei) - - return @basepath + "/engine_env.yaml" \ - if fei.workflow_instance_id == "0" - - wfid = fei.parent_workflow_instance_id - - @basepath + "/" + - wfid[-1, 1] + "/" + - wfid[-2, 1] + "/" + - wfid + "/" + - fei.workflow_instance_id + "__" + - fei.expression_id + "_" + - fei.expression_name + ".yaml" - end + # + # Iterates on each expression that is of the given kind. + # Used for example by the expression pool when rescheduling. + # + def each_of_kind (kind, &block) + + return unless block + + exp_names = get_expression_map.get_expression_names(kind) + #require 'pp' + #pp exp_names + + each_object_path do |path| + + #ldebug { "each_of_kind() path is #{path}" } + + next unless matches(path, exp_names) + + expression = load_object(path) + expression.application_context = @application_context + + block.call expression + end + end + def to_s s = "\n\n==== #{self.class} ====" s << "\n" - Find.find(@basepath) do |path| - if not File.stat(path).directory? - s << path - s << "\n" - end + each_expression_path do |path| + s << path + s << "\n" end s << "==== . ====\n" return s end + + protected + + def compute_file_path (fei) + + return @basepath + "/engine_environment.yaml" \ + if fei.workflow_instance_id == "0" + + wfid = fei.parent_workflow_instance_id + + @basepath + "/" + + wfid[-1, 1] + "/" + + wfid[-2, 1] + "/" + + wfid + "/" + + fei.workflow_instance_id + "__" + + fei.expression_id + "_" + + fei.expression_name + ".yaml" + end + + def matches (path, exp_names) + exp_names.each do |exp_name| + return true \ + if OpenWFE::ends_with(path, "_#{exp_name}.yaml") + end + return false + end end end