Class: OpenWFE::Extras::ActiveParticipant

Inherits:
Object
  • Object
show all
Includes:
LocalParticipant
Defined in:
lib/openwfe/extras/participants/activeparticipants.rb

Overview

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

Direct Known Subclasses

ActiveStoreParticipant

Instance Method Summary collapse

Instance Method Details

#cancel(cancelitem) ⇒ Object

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.



300
301
302
303
# File 'lib/openwfe/extras/participants/activeparticipants.rb', line 300

def cancel (cancelitem)

    Workitem.delete_all([ "fei = ?", cancelitem.fei.to_s ])
end

#consume(workitem) ⇒ Object

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



281
282
283
284
285
286
287
288
289
290
# File 'lib/openwfe/extras/participants/activeparticipants.rb', line 281

def consume (workitem)

    awi = Workitem.from_owfe_workitem(workitem)
        #
        # turns the workitem into an 'active' one

    awi.save
        #
        # and saves it in the db.
end

#reply_to_engine(workitem) ⇒ Object

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.



310
311
312
313
314
315
316
317
318
319
# File 'lib/openwfe/extras/participants/activeparticipants.rb', line 310

def reply_to_engine (workitem)

    super workitem.as_owfe_workitem
        #
        # replies to the workflow engine

    workitem.destroy
        #
        # removes the workitem from the database
end