lib/openwfe/expressions/fe_participant.rb in openwferu-0.9.10.653 vs lib/openwfe/expressions/fe_participant.rb in openwferu-0.9.11

- old
+ new

@@ -80,11 +80,11 @@ # <alpha /> # # The Participant expressions includes the FilterMixin and thus # understands and applies the "filter" attribute. # - # Since OpenWFE 0.9.9, the attributes of the participant expression are + # Since OpenWFEru 0.9.9, the attributes of the participant expression are # set inside a hash field named 'params' just available to the participant. # Thus in # # <participant ref="toto" task="play golf" location="Minami Center" /> # @@ -93,21 +93,31 @@ # { "ref"=>"toto", "task"=>"play golf", "location"=>"Minami Center" }. # # When the workitem gets back from the participant, the field 'params' is # deleted. # + # The participant expressions include the TimeoutMixin, it means that + # a timeout can be stated : + # + # <participant ref="toto" timeout="2w1d" /> + # + # If after 2 weeks and 1 day (15 days), participant "toto" hasn't replied, + # the workitem will get cancelled and the flow will resume (behind the + # scene, participant "toto", will receive a CancelItem instance bearing + # the same FlowExpressionId as the initial workitem and the participant + # implementation is responsible for the cancel application). + # class ParticipantExpression < FlowExpression include FilterMixin include TimeoutMixin names :participant attr_accessor \ :participant_name, :applied_workitem - def apply (workitem) remove_timedout_flag workitem @applied_workitem = workitem.dup @@ -115,24 +125,32 @@ @participant_name = lookup_ref workitem @participant_name = fetch_text_content workitem \ unless @participant_name - determine_timeout() - reschedule(get_scheduler) + schedule_timeout() filter_in workitem store_itself() workitem.params = lookup_attributes workitem get_participant_map.dispatch @participant_name, workitem + get_participant_map.onotify @participant_name, :apply, workitem + # + # these two pmap calls were combined, but with the :reply + # notification in reply_to_parent() it feels more + # elegant like that end def reply_to_parent (workitem) + get_participant_map.onotify @participant_name, :reply, workitem + # + # for 'listen' expressions waiting for replies + unschedule_timeout() workitem.attributes.delete "params" filter_out workitem @@ -145,21 +163,23 @@ # will emit a CancelItem instance towards the participant itself # to notify it of the cancellation. # def cancel + unschedule_timeout() + wi = super() return wi unless @applied_workitem # # have to cancel the workitem on the participant side cancelitem = OpenWFE::CancelItem.new(@applied_workitem) get_participant_map.dispatch(@participant_name, cancelitem) - return nil + nil end # # Upon timeout, the ParticipantExpression will cancel itself and # the flow will resume. @@ -168,10 +188,10 @@ ldebug { "trigger() timeout requested for #{@fei.to_debug_s}" } begin - @scheduler_job_id = nil + #@scheduler_job_id = nil # # so that cancel won't unschedule without need cancel()