Django viewflows - Defining an API flow

こ雲淡風輕ζ 提交于 2019-12-13 17:32:34

问题


I've an API endpoint, /api/create/. This creates a new entry in the DB depending upon the payload received from the client.

Payload - { 
'field1': 'value1`,
'field2': 'value2`,
'field3': 'value3`,
'field4': 'value4`,
'type': 'A'
}

Now depending on the type, I've a specific workflow. For eg:- Type A needs to perform certain tasks before saving the data, Type B has its own set of operations.

I don't have any UI, just the requests coming over the POST request. How can I use django-viewflows for such a use-case?

UPDATED

I was able to run the workflow programmatically using WorkFlowClass.start.run(). It starts the workflow perfectly. However, not the complete workflow. Upon completing Node1(start) of workflow, it does not goes to Node2. Meaning, only first task of the workflow is called, not the subsequent tasks.

Here is my workflow.

class FunctionFlow1(Flow):
    start = flow.StartFunction(function1) \
        .Next(this.task2)
    task2 = flow.StartFunction(function2) \
        .Next(this.end)
    end = flow.End()

@flow_start_func
def function1(activation, **kwargs):
    print('Func1 Called.')
    activation.prepare()
    activation.done()
    return activation

@flow_start_func
def function1(activation, **kwargs):
    print('Func2 Called.')
    activation.prepare()
    activation.done()
    return activation

task2 is not called. Why?


回答1:


You can use viewflow.rest package to create the REST APIs. Please look at the demo project and view flow rest documentation.

Please note that this feature is available in PRO Only

https://github.com/viewflow/cookbook/tree/master/react_ui

http://docs.viewflow.io/viewflow_rest.html

viewflow.rest package provides a flow implementation with the REST interface.



来源:https://stackoverflow.com/questions/48780791/django-viewflows-defining-an-api-flow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!