BPMN dynamic workflow for Django
Asked Answered
D

1

22

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.

Disembark answered 1/3, 2019 at 15:17 Comment(6)
Did you have any luck with this endeavour?Garnet
@alias51Nope. It seems like the most promising path is that someone develop some component that bridges the gap between bpmn_dmn and django-river.Nato
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.Garnet
Did you find a good solution? I'm looking for something similar for a new projectMassacre
There are some additional tips here on django workflow libraries: #6795828Submerse
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.Chloride
M
8

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.

Mcinerney answered 9/12, 2020 at 12:57 Comment(2)
adhesive looks very promising. Did you receive some feedback or support to continue it?Butterfield
@Butterfield No, I did not.Mcinerney

© 2022 - 2024 — McMap. All rights reserved.