lib/openwfe/expressions/fe_participant.rb in openwferu-0.9.2 vs lib/openwfe/expressions/fe_participant.rb in openwferu-0.9.3
- old
+ new
@@ -37,11 +37,13 @@
# "made in Japan"
#
# John Mettraux at openwfe.org
#
+require 'openwfe/utils'
require 'openwfe/rudefinitions'
+require 'openwfe/expressions/timeout'
require 'openwfe/expressions/fe_utils'
#
# The participant expression, in its own file
@@ -54,35 +56,84 @@
# world. The participant expression transmit the workitem applied
# to it to the Participant instance it looks up in the participant map
# tied to the engine.
#
class ParticipantExpression < FlowExpression
+ include TimeoutMixin
attr_accessor \
:participant_name,
:applied_workitem
#
# apply / reply
def apply (workitem)
- @applied_workitem = workitem
- #puts "apply() \n#{@applied_workitem}"
- #ldebug { "apply() \n#{@applied_workitem}" }
+ @applied_workitem = workitem.dup
@participant_name = OpenWFE::lookup_ref(self, workitem)
@participant_name = OpenWFE::fetch_text_content(self, workitem) \
unless @participant_name
+ determine_timeout()
+
store_itself()
- get_participant_map.dispatch(participant_name, workitem)
+ get_participant_map.dispatch(@participant_name, workitem)
end
#def reply (workitem)
#end
+
+ #
+ # The cancel() method of a ParticipantExpression is particular : it
+ # will emit a CancelItem instance towards the participant itself
+ # to notify it of the cancellation.
+ #
+ def cancel
+
+ wi = super()
+
+ if @scheduler_job_id
+ get_scheduler.unschedule(@scheduler_job_id)
+ end
+
+ 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
+ end
+
+ #
+ # Upon timeout, the ParticipantExpression will cancel itself and
+ # the flow will resume.
+ #
+ def trigger (scheduler)
+
+ ldebug { "trigger() timeout requested for #{@fei.to_debug_s}" }
+
+ begin
+
+ @scheduler_job_id = nil
+ #
+ # so that cancel won't unschedule without need
+
+ cancel()
+ reply_to_parent(@applied_workitem)
+ rescue
+ lerror do
+ "trigger() problem while timing out\n"+
+ OpenWFE::exception_to_s($!)
+ end
+ end
+ end
end
end