38

I'm using Django-viewflow to create a workflow programmatically.

This is my flow class.

class Workflow(Flow):

    start = (
        flow.StartFunction(function1)
        .Next(this.shipment_create)
    )

    shipment_create = (
        flow.Function(function2)
        .Next(this.request_quotes)
    )

    request_quotes = (
        flow.Handler(function3)
        .Next(this.move_package)
    )

    move_package = (
        flow.Function(function4)
        .Next(this.end)
    )

    end = flow.End()

What I do is, I start the flow programmatically, when a POST request is made onto an endpoint E1, I run

WorkFLow.start.run(**some_kwargs)

It starts correctly, and after the processing of the start is completed, then the response is returned back to the client.

Now, shipment_create is run when a POST request is made on endpoint E2, and I run it again programmatically via,

activation.flow_task.run(**some_kwargs)

It runs correctly and completes the flow up-to move_package.

THE PROBLEM

I update the details of shipment, via PUT request on endpoint E3, and I want to re-run the complete flow after node shipment_create. How can I do that?

  1. How can I re-run the flow after a specific node?

  2. Point(1) is a manual step, ie programmatically re-run the after nodes. Is there a way, I can include shipment_update node in Workflow class itself so that it automatically re-runs the after-nodes? How and where I would mention update_shipment node?

The problem I see in point(2) is, in one situation I am declaring shipment_create node after start (and the rest Handlers will process), and in another situation I've to mention shipment_update node after start (and the rest Handlers will process). How will the workflow class work according to the type of HTTP method?

Updated

How to return the response of Handler (ie function4)?

def function1():
    return 1


def function2():
    return 2


def function3():
    return 3


def function4():
    return 4

When shipment_create is run, the Handler is executed automatically. However, the response returned is that of shipment_create node, ie function2.

How to return the response of function3(Handler) or How to get the response of the last executed node before sending it back to the client?

Praful Bagai
  • 16,684
  • 50
  • 136
  • 267
  • 1
    The core problem that you don't follow BPMN practice. The goal of BPMN to explicitly describe a flow. You have no "Update details of shipment" on your diagram. You need to redesign your flow according to BPMN practice, with explicit update nodes that would show exactly when shipment update are allowed and what happens after the update. – kmmbvnr Aug 10 '18 at 05:48
  • Understood. Thanks for the response. I'll alter my flow as per the BPMN standards. However, how can I return the response of the `Handler(request_quotes)`, instead of the `Function(shipment_create)`. I mean, when the flow is re-run from `shipment_create`, the response returned is that of the function associated with it. It does not return the response related to `request_quotes`, the handler. – Praful Bagai Aug 14 '18 at 08:20
  • Kindly see the updated question. – Praful Bagai Aug 14 '18 at 08:20
  • Starting a new thread for this question. – Praful Bagai Aug 14 '18 at 10:09
  • https://stackoverflow.com/questions/51839068/django-viewflow-return-handler-response – Praful Bagai Aug 14 '18 at 10:17

0 Answers0