使用 Python 将参数传递给 Cloud Workflows

Pen*_*m10 3 python google-workflows

我正在开发一个 python 脚本,允许我触发云工作流服务。

在脚本中,我在调用
projects/{project}/locations/{location}/workflows/{workflow}/executions端点时传递一些参数。

但我没有找到如何在 YAML 中使用这些参数。

Pen*_*m10 9

要求.txt

google-cloud-workflows>=0.1.0
Run Code Online (Sandbox Code Playgroud)

主要.py

from google.cloud.workflows.executions_v1beta.services.executions import ExecutionsClient
from google.cloud.workflows.executions_v1beta.types import CreateExecutionRequest, Execution
import json

def callWorkflow(request):
    project = "projectid"
    location = "us-central1"
    workflow = "workflowname"
    arguments = {"first": "Hello", "second":"world"}

    parent = "projects/{}/locations/{}/workflows/{}".format(project, location, workflow)
    execution = Execution(argument = json.dumps(arguments))

    client = ExecutionsClient()
    response = None
    # Try running a workflow:
    try:
        response = client.create_execution( parent=parent, execution=execution)
    except:
        return "Error occurred when triggering workflow execution", 500

    return "OK", 200
Run Code Online (Sandbox Code Playgroud)

将其部署为云函数时,请确保函数的服务帐户Workflows.Invoker在 IAM 中设置了角色(触发工作流执行所需)。

部署并运行上述函数后,可以在工作流程中通过以下方式访问参数(示例也可用Docs):

main:
    params: [args]
    steps:
      - firstStep:
          return: ${args.first + " " + args.second}
Run Code Online (Sandbox Code Playgroud)