def order_process()

in services/order-processor/main.py [0:0]


def order_process():
    json_data = request.get_json()
    customer_id, number = None, None
    invalid_fields = []
    for key in json_data.keys():
        if key == 'customer_id':
            customer_id = json_data[key]
        elif key == 'number':
            number = json_data[key]
        else:
            invalid_fields.append(key)
    if customer_id is None or number is None:
        return error500()

    token = get_access_token()

    # Execute workflow
    service_url = 'https://workflowexecutions.googleapis.com/v1beta' \
                  '/projects/{}/locations/{}/workflows/{}/executions'.format(
                      PROJECT_ID, REGION, WORKFLOW)
    headers = {"Authorization": "Bearer {}".format(token),
               "Content-Type": "application/json"}
    data = {"argument": '{{"customer_id":"{}", "number":{}}}'.format(customer_id, number)}
    resp = requests.post(service_url, headers=headers, json=data)
    resp = json.loads(resp.text)
    job_name = resp['name']

    # Wait for the excecution to finish
    service_url = 'https://workflowexecutions.googleapis.com/v1beta/{}'.format(job_name)
    headers = {"Authorization": "Bearer {}".format(token)}
    while True:
        resp = requests.get(service_url, headers=headers)
        resp = json.loads(resp.text)
        state = resp['state']
        if state == 'SUCCEEDED':
            result = json.loads(resp['result'])
            return result, 200
        if state == 'FAILED':
            return error500()
        time.sleep(5)