sartography / SpiffWorkflow

A powerful workflow engine implemented in pure Python
GNU Lesser General Public License v3.0
1.69k stars 313 forks source link

Question: How to send BPMN signals from python and catch them in the BPMN diagram? #400

Closed fro0m closed 5 months ago

fro0m commented 7 months ago

Trying to make BPMN to interact with some external services, so the idea is to get external events in Python and issue signals to the BPMN process running. Please advice how to do it.

essweine commented 7 months ago

The best way to do this is via customizing the script engine. If you run into an error during some sort of external call, the script engine can catch it and send it back to the workflow, using the catch method. I'm actually putting an example of this together, which I can point you to when I finish it, but hopefully this gives you some guidance in the meantime.

essweine commented 7 months ago

This PR https://github.com/sartography/SpiffWorkflow/pull/403 contains documentation for a new example that sends an event to a running workflow based on the outcome of a service task.

fro0m commented 6 months ago

Thank you! Waiting for later details

essweine commented 6 months ago

Here is some example code for generating events: https://github.com/sartography/spiff-example-cli/blob/main/spiff_example/misc/event_handler.py

And the accompanying docs: https://spiffworkflow.readthedocs.io/en/latest/bpmn/script_engine.html#generating-bpmn-events-inside-the-scripting-environment

I actually ended up writing a custom service task instead of using the script engine, because that was easier to do in the example application, but you could do this in either place (there's a note about this in the docs).

Let me know if this helps -- if anything is not clear enough I can attempt to update the docs based on any comments you have.

essweine commented 6 months ago

Did this help answer your question?

essweine commented 5 months ago

Closing since I haven't received any feedback.