mirror of
https://github.com/sartography/spiff-arena.git
synced 2025-01-14 19:44:25 +00:00
c904ee907b
01a25fc3f Merge pull request #333 from sartography/feature/ruff 99c7bd0c7 ruff linting fixes 56d170ba1 Cleaning up badges in the readme. 51c13be93 tweaking action, adding button 96275ad7c Adding a github action to run tests c6c40976a minor fix to please sonarcloud. 03316babb Merge pull request #332 from sartography/updates-for-2.0-release ab70a34b5 Release Notes for 2.0.0_rc1 f0bf79bd9 copy edits a7c726951 Release Notes for 2.0.0_rc1 5f0468ba4 Merge pull request #330 from sartography/updates-for-2.0-release b9ad24406 Mostly minor edits e284dd8e2 corrections and tweaks to documentation 4b2e62600 add more examples 1ea258c6a update spiffworkflow concepts 851d7cdf6 fix a few bugs I found while testing the example repo 7a0a6bdf8 update bpmn docs 07c153f2d save/restore nested subprocess tests 340e9983b Merge branch 'main' of github.com:sartography/spiffworkflow into main 618afbc59 It is rare to submit an update that touches upon both religion and the origins of the universe. I think, for the sake of supporting all view points we must offer the possibility that there can be a thing that is not a child, but rather the beginning of all childen, that there is a chicken to the first egg, a single original big bank. a68dec77e use raw strings for regexes using escape sequences w/ burnettk 4644f2810 Merge pull request #329 from sartography/task/remove-deprecated-functions ca65602c0 correct typo in filename 39ab83f1f remove one deprecated and unused feature 23d54e524 Merge pull request #328 from sartography/improvement/task-spec-attributes 544614aa9 change dmn bpmn_id method to property 12ad185a4 update bpmnworkflow.waiting_events to use classname aec77097d fix some typos & add a few missing licenses 4b87c6d0c add some changes that didn't get included in the merge commit 965a5d4e1 Merge branch 'main' into improvement/task-spec-attributes a844b34f9 alternate bomnworkflow.cancel 0a455cdd2 Merge pull request #327 from sartography/feature/mark_tasks_in_sub_workflows_as_future_if_reseting_to_a_task_before_subworkflow 2bda992aa cancel tasks in subprocesses and return cancelled tasks 309937362 take account that we reset the parent when checking all sub-process executions. d4bcf1290 handle nested subprocesses when resetting tasks 032bedea6 reset subprocess task when resetting a task inside the subprocess 3a6abe157 change reset workflow to drop tasks and re-predict e9cd65757 move exceptions for bpmn into bpmn package e654f2ff1 add bpmn_id and bpmn_name attributes to task specs 74bb9cf1a Found that tasks within a sub-workflow were left in a state of "READY" after resetting to task before the sub-workflow. 957a8faec make all task specs in bpmn processes bpmn tasks b6070005c create actual mixin classes & improve package structure 666a9e4e5 Merge pull request #326 from sartography/feature/boundary_event_reset_fix 9fe5ae4ad Whenever a task is reset who's parent is a "_ParentBoundaryEvent" class, reset to that parent boundary event instead, and execute it, so that all the boundary events are reset to the correct point as well. fbc071af5 remove 'is_engine_step' and use existing 'manual' attribute instead 0d8e53a25 remove unused attributes, minor parser improvements 6ae98b585 Merge pull request #325 from sartography/bugfix/make-data-objects-available-to-gateways cefcd3733 make data objects available to gateways 6060fe778 Merge pull request #324 from sartography/task/update-license efa24bed2 update license 56271f7f7 Merge pull request #323 from sartography/bugfix/handle-dash-in-dmn 6de4e7e01 Merge pull request #322 from sartography/improvement/remove-celery 6ee0668cb remove unnecessary dependencies in test 7ceae68c2 change literal '-' in DMN input to None 4cffc7e7a remove celery task and dependency 580d6e516 Merge pull request #321 from sartography/improvement/allow-duplicate-subprocess-names e4440d4df remove legacy signavio parser 477a23184 remove absolute imports from tests failing in CI 15a812a92 use process ids only when storing process specs abaf1b9e9 move parallel gateway tests to their own package 29fd2d0d9 remove some redundant, unused, or unnecessary tests & consolidate others fda1480bc remove unused CORRELATE attribute from tests 21a2fdbee remove signavio files 299c2613c Merge pull request #320 from sartography/parser_funcs 01afc9f6e PR feedback 646737834 Cleanup dfd3f8214 Add same methods for dmn 764e33ccd Rename file, fix tests 9646abca4 Add bpmn in memory parser functions and tests 58f6bd317 Merge pull request #319 from sartography/feature/better_task_order_for_sub_processes fd7c9308f By swapping the order of these lines, we can assure that a call activity is returned BEFORE the tasks that it contains, rather than after it. 0a7ec19d6 Merge pull request #318 from sartography/feature/optionally-skip-call-activities-when-parsing 3430a2e9f add option to skip parsing call activities 1b1da1dd2 Merge pull request #317 from sartography/bugfix/non-bpmn-tutorial e82345d68 remove some bpmn-related stuff from core serializer 6f9bc279c use name for inputs/outputs in base serializer -- not sure why this was ever changed git-subtree-dir: SpiffWorkflow git-subtree-split: 01a25fc3f829786c4b65d19fd0fda408de37c79f
144 lines
5.4 KiB
ReStructuredText
144 lines
5.4 KiB
ReStructuredText
MultiInstance Tasks
|
|
===================
|
|
|
|
BPMN Model
|
|
----------
|
|
|
|
We'll be using the following files from `spiff-example-cli <https://github.com/sartography/spiff-example-cli>`_.
|
|
|
|
- `multiinstance <https://github.com/sartography/spiff-example-cli/blob/main/bpmn/tutorial/top_level_multi.bpmn>`_ workflow
|
|
- `call activity multi <https://github.com/sartography/spiff-example-cli/blob/main/bpmn/tutorial/call_activity_multi.bpmn>`_ workflow
|
|
- `product_prices <https://github.com/sartography/spiff-example-cli/blob/main/bpmn/tutorial/product_prices.dmn>`_ DMN table
|
|
- `shipping_costs <https://github.com/sartography/spiff-example-cli/blob/main/bpmntutorial//shipping_costs.dmn>`_ DMN table
|
|
|
|
Loop Task
|
|
^^^^^^^^^
|
|
|
|
Suppose we want our customer to be able to select more than one product.
|
|
|
|
We'll run our 'Select and Customize Product' Call Activity as a Loop Task.
|
|
|
|
First we'll update the Call Activity's model to ask the customer if they would like to continue shopping.
|
|
|
|
.. figure:: figures/multiinstance/call_activity_multi.png
|
|
:scale: 30%
|
|
:align: center
|
|
|
|
Selecting more than one product
|
|
|
|
We've also added a *postScript* to the user task. Spiffworkflow provides extensions that allow scripts to be
|
|
run before and after tasks. It is often the case that data needs to be manipulated before and after a task.
|
|
We could add regular Script Tasks before and after, but diagrams quickly become cluttered with scripts, and
|
|
these extensions are intended to alleviate that.
|
|
|
|
We use a *postScript* to add the current product to a list of products.
|
|
|
|
.. code:: python
|
|
|
|
products.append({
|
|
'product_name': product_name,
|
|
'product_quantity': product_quantity,
|
|
'product_color': product_color,
|
|
'product_size': product_size,
|
|
'product_style': product_style,
|
|
'product_price': product_price,
|
|
})
|
|
|
|
We'll use a *preScript* on the first User Task (Select Product and Quantity) to initialize these variables to
|
|
:code:`None` each time we execute the task.
|
|
|
|
Loop Tasks run either a specified number of times or until a completion condition is met. Since we can't
|
|
know in advance how many products the customer will select, we'll add :code:`continue_shopping == 'Y'` as a
|
|
completion condition. We'll re-run this Call Activity as long as the customer indicates they want to choose
|
|
another product. We'll also set up the list of products that we plan on appending to.
|
|
|
|
We also added a postscript to this activity to delete the customization values so that we won't have to
|
|
look at them for the remainder of the workflow.
|
|
|
|
.. figure:: figures/multiinstance/loop_task.png
|
|
:scale: 30%
|
|
:align: center
|
|
|
|
Call Activity with Loop
|
|
|
|
We also needed to update our Script Task and the Instructions of the Review Order Task to handle an array
|
|
of products rather than a single product.
|
|
|
|
Here is our new script
|
|
|
|
.. code:: python
|
|
|
|
order_total = sum([ p['product_quantity'] * p['product_price'] for p in products ]) + shipping_cost
|
|
|
|
And our order summary
|
|
|
|
.. code:: python
|
|
|
|
Order Summary
|
|
{% for product in products %}
|
|
{{ product['product_name'] }}
|
|
Quantity: {{ product['product_quantity'] }}
|
|
Price: {{ product['product_price'] }}
|
|
{% endfor %}
|
|
Shipping Cost: {{ shipping_cost }}
|
|
Order Total: {{ order_total }}
|
|
|
|
Parallel MultiInstance
|
|
^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
We'll also update our 'Retrieve Product' Task and 'Product Not Available' flows to
|
|
accommodate multiple products. We can use a Parallel MultiInstance for this, since
|
|
it does not matter what order our Employee retrieves the products in.
|
|
|
|
.. figure:: figures/multiinstance/multiinstance_task_configuration.png
|
|
:scale: 30%
|
|
:align: center
|
|
|
|
MultiInstance Task configuration
|
|
|
|
We've specified :code:`products` as our Input Collection and :code:`product` as our Input Item. The
|
|
Input Collection should be an existing collection. We'll create a task instance for each element of
|
|
the collection, and copy the value into the Input Item; this is how we'll access the data of the
|
|
element.
|
|
|
|
.. :code::
|
|
|
|
Item: {{product['product_quantity']}} of {{product['product_name']}}
|
|
|
|
We also specified :code:`availability` as our Output Collection. Since this variable does not exist,
|
|
SpiffWorkflow will automatically create it. You can use an existing variable as an Output Collection;
|
|
in this case, its contents will be updated with new values. The Output Item will be copied out of the
|
|
child task into the Output Collection.
|
|
|
|
The 'Retrieve Product' task creates :code:`product_available` from the form input.
|
|
|
|
Since our input is a list, our output will also be a list. It is possible to generate different output
|
|
types if you create the output collections before referring to them.
|
|
|
|
We have to update our gateway condition to handle the list:
|
|
|
|
.. figure:: figures/multiinstance/availability_flow.png
|
|
:scale: 60%
|
|
:align: center
|
|
|
|
Gateway Condition
|
|
|
|
|
|
Sequential MultiInstance
|
|
^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
SpiffWorkflow also supports Sequential MultiInstance Tasks for collections, or if the loopCardinality
|
|
is known in advance, although we have not added an example of this to our workflow. Their configuraiton
|
|
is almost idenitcal to the configuration for Parallel MultiInstance Tasks.
|
|
|
|
Running The Model
|
|
^^^^^^^^^^^^^^^^^
|
|
|
|
If you have set up our example repository, this model can be run with the following command:
|
|
|
|
.. code-block:: console
|
|
|
|
./spiff-bpmn-runner.py -p order_product \
|
|
-d bpmn/tutorial/product_prices.dmn bpmn/tutorial/shipping_costs.dmn \
|
|
-b bpmn/tutorial/top_level_multi.bpmn bpmn/tutorial/call_activity_multi.bpmn
|