lib/openwfe/engine/engine.rb in openwferu-0.9.9 vs lib/openwfe/engine/engine.rb in openwferu-0.9.10

- old
+ new

@@ -126,17 +126,14 @@ # Launches a [business] process. # The 'launch_object' param may contain either a LaunchItem instance, # either a String containing the URL of the process definition # to launch (with an empty LaunchItem created on the fly). # - # If async is set to true, the process will be launched asynchronously - # (in his own thread). + # Returns the FlowExpressionId instance of the expression at the + # root of the newly launched process. # - # Returns a FlowExpressionId instance or a tuple FlowExpressionId / - # Thread object if async is set to true. - # - def launch (launch_object, async=false) + def launch (launch_object) launchitem = if launch_object.kind_of?(OpenWFE::LaunchItem) launch_object @@ -156,11 +153,11 @@ end li end - get_expression_pool.launch launchitem, async + get_expression_pool.launch launchitem end # # This method is used to feed a workitem back to the engine (after # it got sent to a worklist or wherever by a participant). @@ -170,15 +167,15 @@ # def reply (workitem) if workitem.kind_of?(InFlowWorkItem) - get_expression_pool.reply(workitem.flow_expression_id, workitem) + get_expression_pool.reply workitem.flow_expression_id, workitem elsif workitem.kind_of?(LaunchItem) - get_expression_pool.launch(workitem, false) + get_expression_pool.launch workitem else raise \ "engine.reply() " + @@ -298,20 +295,21 @@ def enable_irb_console OpenWFE::trap_int_irb(binding) end - # + #-- # Makes sure that hitting CTRL-C will actually kill the engine VM and # not open an IRB console. # #def disable_irb_console # $openwfe_irb = nil # trap 'INT' do # exit 0 # end #end + #++ # # Stopping the engine will stop all the services in the # application context. # @@ -394,9 +392,47 @@ # Forgets the given expression (make it an orphan) # (warning : advanced method) # def forget_expression (exp_or_fei) get_expression_pool.forget(exp_or_fei) + end + + # + # Waits for a given process instance to terminate. + # The method only exits when the flow terminates, but beware : if + # the process already terminated, the method will never exit. + # + # The parameter can be a FlowExpressionId instance, for example the + # one given back by a launch(), or directly a workflow instance id + # (String). + # + # This method is mainly used in utests. + # + def wait_for (fei_or_wfid) + + wfid = if fei_or_wfid.kind_of?(FlowExpressionId) + fei_or_wfid.workflow_instance_id + else + fei_or_wfid + end + + #Thread.pass + # # + # # let the flow 'stabilize' or progress before enquiring + #fexp = get_expression_pool.fetch_expression(fei) + #return unless fexp + # + # doesn't work well + + t = Thread.new { Thread.stop } + + get_expression_pool.add_observer(:terminate) do |channel, fe, wi| + t.wakeup if fe.fei.workflow_instance_id == wfid + end + + ldebug { "wait_for() #{wfid}" } + + t.join end protected #