Class OpenWFE::Extras::ActiveParticipant

  1. lib/openwfe/extras/participants/active_participants.rb
Parent: Object

A basic ‘ActiveParticipant’. A store participant whose store is a set of ActiveRecord tables.

Sample usage :

 class MyDefinition < OpenWFE::ProcessDefinition
   sequence do
     active0
     active1
   end
 end

 def play_with_the_engine

   engine = OpenWFE::Engine.new

   engine.register_participant(
     :active0, OpenWFE::Extras::ActiveParticipant)
   engine.register_participant(
     :active1, OpenWFE::Extras::ActiveParticipant)

   li = OpenWFE::LaunchItem.new(MyDefinition)
   li.customer_name = 'toto'
   engine.launch li

   sleep 0.500
     # give some slack to the engine, it's asynchronous after all

   wi = OpenWFE::Extras::Workitem.find_by_participant_name("active0")

   # ...
end

Compact workitems

It is possible to save all the workitem data into a single table, the workitems table, without splitting info between workitems and fields tables.

You can configure the “compact_workitems“ behavior by adding to the previous lines:

active0 = engine.register_participant(
  :active0, OpenWFE::Extras::ActiveParticipant)

active0.compact_workitems = true

This behaviour is determined participant per participant, it’s ok to have a participant instance that compacts will there is another that doesn’t compact.

Methods

public instance

  1. cancel
  2. consume
  3. do_not_thread
  4. reply_to_engine

Included modules

  1. OpenWFE::LocalParticipant

Attributes

compact_workitems [RW] when compact_workitems is set to true, the attributes of a workitem are stored in the yattributes column (they are not expanded into the Fields table). By default, workitem attributes are expanded.

Public instance methods

cancel (cancelitem)

Called by the engine when the whole process instance (or just the segment of it that sports this participant) is cancelled. Will removed the workitem with the same fei as the cancelitem from the database.

No expression will be raised if there is no corresponding workitem.

[show source]
     # File lib/openwfe/extras/participants/active_participants.rb, line 658
658:     def cancel (cancelitem)
659: 
660:       Workitem.destroy_all([ 'fei = ?', cancelitem.fei.to_s ])
661:         # note that delete_all was not removing workitem fields
662:         # probably my fault (bad :has_many setting)
663:     end
consume (workitem)

This is the method called by the OpenWFEru engine to hand a workitem to this participant.

[show source]
     # File lib/openwfe/extras/participants/active_participants.rb, line 642
642:     def consume (workitem)
643: 
644:       workitem.attributes['compact_workitems'] = true if compact_workitems
645: 
646:       Workitem.from_owfe_workitem workitem
647:         # does the 'saving to db'
648:     end
do_not_thread ()

Forces ruote to not spawn a thread when dispatching to this participant.

[show source]
     # File lib/openwfe/extras/participants/active_participants.rb, line 634
634:     def do_not_thread
635:       true
636:     end
reply_to_engine (workitem)

When the activity/work/operation whatever is over and the flow should resume, this is the method to use to hand back the [modified] workitem to the [local] engine.

[show source]
     # File lib/openwfe/extras/participants/active_participants.rb, line 670
670:     def reply_to_engine (workitem)
671: 
672:       super(workitem.as_owfe_workitem)
673:         #
674:         # replies to the workflow engine
675: 
676:       workitem.destroy
677:         #
678:         # removes the workitem from the database
679:     end