We know that a subprocess should be started for n
items when the task is activated, however, during the lifetime of the NSubprocess
task, additional items could be found.
Let's say we have Order
and OrderItem
. When a customer submits an order and the flow gets to fulfill_orderitems
(NSubprocess
- FulfillOrderItem
flow) task, we start the subprocess for each order item.
However, during the lifetime of this fulfill_orderitems
task the customer can contact us to add additional item to the order. At this point we are forced to create a new Order
process which is a bit tedioius; whereas if we could simply initiate a new FulfillOrderItem
subprocess then things remain much simpler.
Obviously once the fulfill_orderitems
is done and the customer calls afterwards to add additional item, then we'd have to either roll back (unpractical) or make a new Order
process.
This is just a simple example, but generally speaking this behavior is quite useful. One could argue this should be a core functionality of NSubprocess
(ie. to be able to add additional n+1
subprocess during the liftetime of the task). How would one go about doing this?
We need to handle 2 things (from what I can see):
- Function that starts this additional process. From what I understand it could be as simple as:
@Activation.status.transition(source=STATUS.STARTED)
def start_subprocess(self, item):
self.flow_task.subflow_task.run(self.task, item)
- The view where the
item
is submitted through a form. Alternatively submit it through code directly. This bit I have trouble coming up with. It should be relatively simple, because it is very similar to whatStartSubprocess
does... (but we need to call the aforementionedstart_subprocess(item)
? However, I'm more interested in being able to call the method directly (eg throughDRF
).