What is the best way to invoke a subprocess n times

  • 27 July 2010
  • 3 replies
  • 3 views

Badge +1

I have a requirement for the main process to invoke a subprocess n times. When all subprocesses are complete the main process resumes.


I was thinking of using a server event to start the processes (based on a user entered number) and then have each subprocess update a counter. The main process would then restart when the counter reached the number of subprocesses started.


Is this OK? Do I have to worry about locking the counter on update? Do I have to worry about the main process polling the counter continuously?


3 replies

Badge +5

This can be done via the Advanced Destination Rule settings on an Activity - 'Plan per slot (no destinations)' in conjunction with an IPC event and the Suceeding Rule of the Activity in the parent process.  Basically a GetList method from a SmartObject or a repeating field in an XML document can be used and will execute n-times based on the number of rows returned from a GetList method or the number of sections in a repeating section of an XML document.  The Succeeding Rule can be set to 'All of ActivityInstDestStatus = Completed' to ensure that all child processes are complete prior to moving forward in the parent process.  The K2 blackpearl book has an example on page 850.  This link: http://blogs.claritycon.com/blogs/tim_byrne/archive/2008/04/17/stumbling-through-k2-blackpearl-for-each-loop-simulation.aspx has some more information regarding using XML.  There was a good tutorial somewhere here on the Underground a while back, but I can't seem to find it now.  Perhaps someone else can chime in with references.


If you just have a static number that you want to decrement with each loop, don't need the advanced functionality mentioned above, or don't have a repeating rows/sections, then you could use a process level data field to store the counter, execute your IPC event, a server event at the end of the same activity to decrement the counter (either through code or through inline functions if 4.5) and then a loop back line to the same activity if the counter > 0. 


 

Badge +1

Thanks - I think I will got with the second option.


Do I have to worry about locking (i.e. do the child processes really run in parrallel or just on a turn-by-turn basis)?

Badge +5

If you run the child process synchronously then the parent process stops execution altogether until the child completes.  If you run the child process asynchronously then both processes will run in parallel.  You cannot pass data back to the parent process when calling asynchronously (via the wizard).  However, you could use an external data store (i.e. SmartObject and not process level data field) to share data between the two processes.  This is a scenario where you would need to be concerned with shared data being overwritten by each processes.

Reply