18

I want to build a Django solution which workflow can be defined and changed on the fly, hopefully by updating a BPMN diagram without having to change the source code and redeploy.

Despite such a feature has been around for quite a while in Java (i.e. Camunda and Bizagi), in the context of Django it seems to have not sparked the same interest since the usual places where I searched did not provide any satisfactory answers. The answers to a similar question from 2011 revealed that the term "workflow" is so wide that could mean many things. However, after some scrutiny it seems to boil down to two approaches: Django-based workflows and BPMN engines.

The problem with Django-based workflows listed in Github and Django packages is that the most popular/stable (for example Viewflow or ActivFlow) provide some kind of framework to ease the implementation of your states and transitions but, at the end of the day, you need to code changes by hand each time that the stakeholders change their mind about the process flow. The most promising option found at the awesome Django list was django-river which at least stores the states and transitions of the workflow as Django models in the database, so you can make changes on the fly.

The other big approach is BPMN engines. After messing around with several Python-pure (non Django) options, I manage to get SpiffWorkflow working using bpmn_dmn. Now I can load .bpmn diagrams and .dmn tables made with Camunda Modeler and run them through the engine to get a final event based on some parameters.

    from bpmn_dmn.bpmn_dmn import BPMNDMNXMLWorkflowRunner
    filename = 'rates.bpmn'
    runner = BPMNDMNXMLWorkflowRunner(filename, debugLog='DEBUG', debug=False)
    data = {'size': 150, 'type': 'SH', 'country': 'US'}
    runner.start(**data)
    res = runner.getEndEventName()
    print(res)

This is straightforward and useful enough to run small workflows that do not require human intervention. However I still need to bridge the gap between a workflow loaded from a .bpmn diagram definition and the transitions between Views/Forms/Model states inherent to a Django solution.

So far my best option seems to be to translate the workflow specification from SpiffWorflow into states/transitions records in the django-river models database, but I wonder whether there is a better option out there.

Ahmet DAL
  • 3,927
  • 6
  • 43
  • 66
  • Did you have any luck with this endeavour? – alias51 Aug 27 '19 at 16:12
  • 1
    @alias51Nope. It seems like the most promising path is that someone develop some component that bridges the gap between bpmn_dmn and django-river. – Andrés Meza-Escallón Aug 28 '19 at 21:56
  • 1
    Postgres (9.4+?) offers queryable JSONb fields. If you want a hackish approach you could set workflow parameters in JSON and then write a framework to query them. – alias51 Aug 28 '19 at 23:01
  • Did you find a good solution? I'm looking for something similar for a new project – yvess Aug 20 '20 at 08:14
  • There are some additional tips here on django workflow libraries: https://stackoverflow.com/questions/6795328/workflow-frameworks-for-django – FGiorlando Oct 25 '20 at 01:25
  • Pretty sure there isn't anything. I recently started looking at putting a python package together for "BPMN as code", that would generate SVG diagrams, with the goal of later being able to connect it into eg. Rabbit/Celery to handle the workflows. Doubt I'm good enough to get this done tbh :D But I did search around for a decent BPMN solution, and couldn't find anything useful. – michjnich Nov 18 '20 at 09:29

1 Answers1

4

A while ago, I made a pure python micro BPMN engine called adhesive that can execute BPMN files. Besides parallelism (via processes or threads), error handling, timers, external events, lanes, scripts, gateways, edge conditions, or tasks, it also supports User Tasks.

While the User Tasks system is made to be pluggable, in reality, there's a single implementation, and that one uses ncurses. This is how the UI actually looks when entering one of those elements:

enter image description here

If more people think this would be interesting, I could invest some time to create a bridge that whenever a "django" User Task gets hit, it would integrate with Django in some meaningful form.

bogdan.mustiata
  • 1,257
  • 10
  • 20