BPMN dynamic workflow for Django

5.1k views Asked by At

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.

1

There are 1 answers

2
bogdan.mustiata On

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.