def deploy_workflow(self, process_id, definition, channel=None): stub = gateway_pb2_grpc.GatewayStub(channel) workflow = gateway_pb2.WorkflowRequestObject( name=process_id, type=gateway_pb2.WorkflowRequestObject.BPMN, definition=definition) return [ stub.DeployWorkflow( gateway_pb2.DeployWorkflowRequest(workflows=[workflow])) ]
def job_iterator(self, _type, worker_name, timeout=30, max=1, channel=None): stub = gateway_pb2_grpc.GatewayStub(channel) activate_jobs_response = stub.ActivateJobs( gateway_pb2.ActivateJobsRequest(type=_type, worker=worker_name, timeout=timeout, maxJobsToActivate=max)) for response in activate_jobs_response: for job in response.jobs: yield ZeebeJob(stub, job)
def startWorkflowInstances(numberOfInstances, payload): print("## Start Workflow Instances ") start = timer() file = open('payloads/payload-' + payload + '.json', 'r') payload = file.read() with grpc.insecure_channel("localhost:26500") as channel: stub = gateway_pb2_grpc.GatewayStub(channel) for i in range(0, numberOfInstances): stub.CreateWorkflowInstance( gateway_pb2.CreateWorkflowInstanceRequest( bpmnProcessId='ping-pong', version=-1, variables=payload.replace('RANDOM', str(uuid.uuid1())))) print("Started workflows instances: " + str(timedelta(seconds=timer() - start)))
def create_instance(self, process_id, variables=None, version=1, channel=None): stub = gateway_pb2_grpc.GatewayStub(channel) res = stub.CreateWorkflowInstance( gateway_pb2.CreateWorkflowInstanceRequest( bpmnProcessId=process_id, version=version, variables=json.dumps(variables) if variables else json.dumps({}))) # make object json serializable return [{ k: getattr(res, k) for k in ['bpmnProcessId', 'version', 'workflowInstanceKey', 'workflowKey'] }]
# 使用cursor()方法获取操作游标 cursor = db.cursor() # SQL 插入语句 sql = "INSERT INTO tab_productinfo\ (Guid_product, Product_name, Operation_name, Operation_machine_name, Operation_machine_ID) \ VALUES('%s', '%s', '%s', '%s', '%s')" % \ (productID_str[target_index_result], product_str[target_index_result], \ process_str[target_index_result], resource_str[target_index_result], resourceID_str[target_index_result]) try: # 执行sql语句 cursor.execute(sql) # 执行sql语句 db.commit() except: # 发生错误时回滚 db.rollback() # 关闭数据库连接 db.close() return 0 while True: with grpc.insecure_channel(ZEEBE_GATEWAY) as channel: stub = gateway_pb2_grpc.GatewayStub(channel) for jobResponse in stub.ActivateJobs(gateway_pb2.ActivateJobsRequest(type = 'payment-service', worker = 'ppr-client', timeout = 10000, maxJobsToActivate = 32)): for job in jobResponse.jobs: print(job) PPR_main() stub.CompleteJob(gateway_pb2.CompleteJobRequest(jobKey = job.key))
def get_topology(self, channel=None): stub = gateway_pb2_grpc.GatewayStub(channel) topology = stub.Topology(gateway_pb2.TopologyRequest()) return [topology]
def __init__(self): channel = grpc.insecure_channel("%s:%s" % (ZEEBE_HOST, ZEEBE_PORT)) self.stub = gateway_pb2_grpc.GatewayStub(channel)