Upgrade to Pro — share decks privately, control downloads, hide ads and more …

PyConZA 2012: "Executing BPMN 2.0 workflows in ...

Pycon ZA
October 04, 2012

PyConZA 2012: "Executing BPMN 2.0 workflows in Python" by Matt Hampton

BPMN (Business Processing Model and Notation) is a widely used standard for specifying business processes in a graphical notation. Version 2.0 of the specification includes a standardized XML serialization of that notation.

We've recently adapted SpiffWorkflow, an open source Python workflow library, to import BPMN2 specifications and execute them. In our implementation, the workflow runs on individual database records and defines the life cycle of those records.

The advantage of this is that we can use several available graphical tools for defining business processes, and then have those business processes automatically executable inside our applications. This increases the clarity of definition of these processes, makes them explicitly visible to non-developers, and also potentially modifiable by them. It also decouples the business logic flow from the actual code processes that need to happen at various points.

This talk will briefly explain the core BPMN concepts, demonstrated with graphical editing tools, and demonstrate how the SpiffWorkflow implementation works.

* Workflow and the need for clarity rather than ambiguity -- how BPMN achieves this
* BPMN core concepts, demonstrated graphically
* Demonstration of SpiffWorkflow objects executing BPMN diagrams
* Questions time...

Pycon ZA

October 04, 2012
Tweet

More Decks by Pycon ZA

Other Decks in Programming

Transcript

  1. Outline •A Tale of Woe •Business Process Model and Notation

    •SpiffWorkflow o And the Workflow Patterns initiative •SpiffWorkflow + BPMN •Recommended Use Case •Q & A
  2. Outline •A Tale of Woe •Business Process Model and Notation

    •SpiffWorkflow o And the Workflow Patterns initiative •SpiffWorkflow + BPMN •Recommended Use Case •Q & A
  3. def get_close_button_rights(self): """Whether or not the user has the right

    to click the Close (Isolations Removed) button""" if self.status in ('Complete','Reactivated','Closed (Isolations Maintained)'): session = RequestStack.request_stack.session if session: if self.approved_by == session.user: permit_work_table = Alchemy.find_recordclass("permit_work") with Alchemy.closing(self.session_class()) as sa_session: associated_permits = sa_session.query(permit_work_table).filter(sqlalchemy.and_(permit_wo if self.master_permit == 'Yes': if not associated_permits and (self.num_isolation_points in (0, '0') or self.points_d if self.gs_required == u"Yes": if self.gs_test_due == u"False" or self.gs_button_clicked == "Yes": return 'True' else: return 'True' elif (not self.num_isolation_points in (0, '0') or associated_permits) and self.check if self.gs_required == u"Yes": if self.gs_test_due == u"False" or self.gs_button_clicked == "Yes": return 'True' else: return 'True' elif (self.points_deisolated == 'True' or self.category in ("Vehicle", "Lifting")): if self.gs_required == u"Yes": if self.gs_test_due == u"False" or self.gs_button_clicked == "Yes": return 'True' else: return 'True' elif self.status == 'Incomplete': #If the status is Incomplete this button is a Reissue button session = RequestStack.request_stack.session if session: if self.approved_by == session.user: return 'True' return 'False' close_button_rights = property(get_close_button_rights)
  4. Gratuitous Gang of Four Quote •Use the State pattern if:

    o Operations have large, multipart conditional statements that depend on the object’s state. The state is usually represented by one or more enumerated constants. Often, several operations will contain this same conditional structure. o Hmmm.
  5. OMG(!) BPMN •Object Management Group •Business Process Modelling Notation (v1)

    o Business Friendly notation in wide use o Unambiguous semantics o Clear analysis / communication of requirements o Asking the right questions •Business Process Model and Notation (v2) o Executable Process Definitions o http://www.bpmn.org
  6. Outline •A Tale of Woe •Business Process Model and Notation

    •SpiffWorkflow o And the Workflow Patterns initiative •SpiffWorkflow + BPMN •Recommended Use Case •Q & A
  7. SpiffWorkflow •Pure Python Library •Based on the Worklow Patterns initiative

    o http://www.workflowpatterns.com •Build a ‘Workflow Spec’ •Create a ‘Workflow’ instance •API for getting a list of READY / WAITING tasks o Completing a task, moves the workflow forward •Maintained by Samuel Abels
  8. class MyWorkflowSpec(WorkflowSpec): def __init__(self): WorkflowSpec.__init__(self) # Build one branch. a1

    = Simple(self, 'task_a1') self.start.connect(a1) a2 = Simple(self, 'task_a2') a1.connect(a2) # Build another branch. b1 = Simple(self, 'task_b1') self.start.connect(b1) b2 = Simple(self, 'task_b2') b1.connect(b2) # Merge both branches (synchronized). synch_1 = Join(self, 'synch_1') a2.connect(synch_1) b2.connect(synch_1) # If-condition: excl_choice_1 = ExclusiveChoice(self, 'excl_choice_1') synch_1.connect(excl_choice_1) c1 = Simple(self, 'task_c1') excl_choice_1.connect(c1) c2 = Simple(self, 'task_c2') cond = Equal(Attrib('test_attribute1'), Attrib('test_attribute2')) excl_choice_1.connect_if(cond, c2) c3 = Simple(self, 'task_c3') excl_choice_1.connect_if(cond, c3)
  9. Control Flow Features •Sequence •Parallel Split •Exclusive Choice •Simple Merge

    •Multi-Choice •Structured Synchronizing Merge •…..
  10. Outline •A Tale of Woe •Business Process Model and Notation

    •SpiffWorkflow o And the Workflow Patterns initiative •SpiffWorkflow + BPMN •Recommended Use Case •Q & A
  11. SpiffWorkflow + BPMN •Pluggable Parser •Extensible Task Spec classes o

    Allows the use of BPMN extension elements •Pluggable Script Engine o Executes script tasks o Evaluates expressions •Database-friendly Workflow Serialization
  12. Supported BPMN Features •Call Activity •Start Event •End Event (including

    interrupting) •User and Manual Tasks •Script Task
  13. Supported BPMN Features •Exclusive Gateway •Parallel Gateway •Intermediate Catch Events

    (Timer and Message) •Boundary Events (Timer and Message, interrupting and non- interrupting)
  14. Project Status •BPMN extension is currently in a fork: o

    https://github.com/matthewhampton/SpiffWorkf o Should be merged in to the base project in the next month •Gemsbok is here: o https://github.com/matthewhampton/Gemsbok •Eclipse BPMN2 Modeler is here: o http://eclipse.org/bpmn2-modeler
  15. Outline •A Tale of Woe •Business Process Model and Notation

    •SpiffWorkflow o And the Workflow Patterns initiative •SpiffWorkflow + BPMN •Recommended Use Case •Q & A
  16. Is BPMN for you? •Small number of states? o Use

    the State Pattern, or a similar OO decomposition •Single-threaded & No Actions on Transitions o Table-based State Machine •Complex workflows? •Getting tied up in specification round trips? •Like Pretty Pictures? OMG BPMN!
  17. Outline •A Tale of Woe •Business Process Model and Notation

    •SpiffWorkflow o And the Workflow Patterns initiative •SpiffWorkflow + BPMN •Recommended Use Case •Q & A
  18. ?

  19. ?