Python客户端司机
pyconductor的Python项目详细描述
导体的python客户端
python client for conductor提供两组函数:
- 工作流管理API(启动、终止、获取工作流状态等)
- 工人执行框架
NOTE: This repository has been forked from Netflix:conductor's
client/python
folder. Apart from the results of renaming the module fromconductor
topyconductor
, (as pip already contains aconductor
module), there are no code changes. This repository is mostly meant to act as an easy way to install the python client forNetflix:conductor
. There are also attempts made to add documentation to the client overall. As far as possible, the library will be kept in sync with the upstream branch.
安装
pip install pyconductor
使用工作流管理API
python类WorkflowClient
向指挥服务器提供客户端api调用,以开始管理工作流。
示例
importsysfrompyconductorimportconductorimportjsondefgetStatus(workflowId):workflowClient=conductor.WorkflowClient('http://localhost:8080/api')workflow_json=workflowClient.getWorkflow(workflowId)printjson.dumps(workflow_json,indent=True,separators=(',',': '))returnworkflow_json
任务工作线程执行
任务工作线程执行api使用python客户机促进任务工作线程的执行。 api提供了必要的机制,可以定期轮询任务工作,并在单独的线程中执行python工作线程。
示例
下面的python脚本演示kitchensink工作流的工作人员。
frompyconductor.ConductorWorkerimportConductorWorkerdefexecute(task):return{'status':'COMPLETED','output':{'mod':5,'taskToExecute':'task_1','oddEven':0},'logs':['one','two']}defexecute4(task):forkTasks=[{"name":"task_1","taskReferenceName":"task_1_1","type":"SIMPLE"},{"name":"sub_workflow_4","taskReferenceName":"wf_dyn","type":"SUB_WORKFLOW","subWorkflowParam":{"name":"sub_flow_1"}}];input={'task_1_1':{},'wf_dyn':{}}return{'status':'COMPLETED','output':{'mod':5,'taskToExecute':'task_1','oddEven':0,'dynamicTasks':forkTasks,'inputs':input}}defmain():print'Hello World'cc=ConductorWorker('http://localhost:8080/api',1,0.1)forxinrange(1,30):if(x==4):cc.start('task_{0}'.format(x),execute4,False)else:cc.start('task_{0}'.format(x),execute,False)cc.start('task_30',execute,True)if__name__=='__main__':main()