lib/openwfe/worklist/storeparticipant.rb in openwferu-0.9.5 vs lib/openwfe/worklist/storeparticipant.rb in openwferu-0.9.6

- old
+ new

@@ -37,10 +37,11 @@ # # John Mettraux at openwfe.org # require 'openwfe/utils' +require 'openwfe/rudefinitions' require 'openwfe/storage/yamlfilestorage' require 'openwfe/participants/participant' module OpenWFE @@ -133,26 +134,65 @@ if (not workflow_instance_id) or workitem.fei.parent_wfid == workflow_instance_id end return result end + + # + # Returns the first workitem at hand. + # As a StoreParticipant is usually implemented with a hash, two + # consecutive calls to this method might not return the same workitem + # (except if the store is empty or contains 1! workitem). + # + def first_workitem () + + result = nil + + self.each_value do |workitem| + result = workitem + break + end + + return result + end end # # The simplest workitem store possible, gathers the workitem in a # hash (this class is an extension of Hash). # + # Some examples : + # + # engine.register_participant(:alice, OpenWFE::HashParticipant) + # engine.register_participant("bob", OpenWFE::HashParticipant) + # + # hp = engine.register_participant(:charly, OpenWFE::HashParticipant) + # #... + # puts "there are currently #{hp.size} workitems for Charly" + # + # hp = OpenWFE::HashParticipant.new + # engine.register_participant("debbie", hp) + # class HashParticipant < Hash include StoreParticipantMixin # that's all... end # # Implementation of a store participant stores the workitems in # yaml file in a dedicated directory. # + # It's quite easy to register a YamlParticipant : + # + # yp = engine.register_participant(:alex, YamlParticipant) + # + # puts yp.dirname + # + # should yield "./work/participants/alex/" (if the key :work_directory + # in engine.application_context is unset) + # class YamlParticipant < YamlFileStorage include StoreParticipantMixin attr_accessor :dirname @@ -161,17 +201,17 @@ # application_context. # The dirname should be a simple name acceptable as a filename. # def initialize (dirname, application_context) + workdir = application_context[:work_directory] + workdir = OpenWFE::DEFAULT_WORK_DIRECTORY unless workdir + @dirname = OpenWFE::ensure_for_filename(dirname.to_s) service_name = @self.class.name + "__" + @dirname - path = - application_context[:work_directory] + - "/participants/" + - @dirname + path = workdir + "/participants/" + @dirname super(service_name, application_context, path) end protected