1

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

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

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

4

1 回答 1

4

要求.txt

google-cloud-workflows>=0.1.0

主文件

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

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

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

main:
    params: [args]
    steps:
      - firstStep:
          return: ${args.first + " " + args.second}
于 2020-11-20T19:31:43.887 回答