适用于 Cloud Tasks 的连接器

定义用于在工作流内访问 Cloud Tasks 的内置函数的 Workflows 连接器。

包含此代码示例的文档页面

如需查看代码示例的实际使用场景,请参阅以下文档:

代码示例

YAML

# This workflow demonstrates how to use the Cloud Tasks connector.
# The workflow creates a Cloud Tasks queue, creates a task in that queue,
# and then deletes the task and the queue.
# Expected successful output: "SUCCESS"

- init:
    assign:
    - project_id: ${sys.get_env("GOOGLE_CLOUD_PROJECT_ID")}
    - location_id: "us-central1"
    - queue_id: "dummy-queue-id"
    - task_id: "dummy-task-id"
    - schedule_time: "[fill this in]"  # The time when the task is scheduled to be attempted or retried. Must be in RFC3339 UTC "Zulu" format, examples: "2014-10-02T15:01:23Z" and "2014-10-02T15:01:23.045123456Z".
    - cloud_function_url: "[fill this in]"  # The Cloud Function to be triggered by the task.
- create_queue:
    call: googleapis.cloudtasks.v2.projects.locations.queues.create
    args:
      parent: ${"projects/" + project_id + "/locations/" + location_id}
      body:
        name: ${"projects/" + project_id + "/locations/" + location_id + "/queues/" + queue_id}
    result: queue
- create_task:
    call: googleapis.cloudtasks.v2.projects.locations.queues.tasks.create
    args:
      parent: ${queue.name}
      body:
        task:
          name: ${queue.name + "/tasks/" + task_id}
          scheduleTime: ${schedule_time}
          httpRequest:
            url: ${cloud_function_url}
            httpMethod: "GET"
    result: task
- get_task:
    call: googleapis.cloudtasks.v2.projects.locations.queues.tasks.get
    args:
      name: ${task.name}
- delete_task:
    call: googleapis.cloudtasks.v2.projects.locations.queues.tasks.delete
    args:
      name: ${task.name}
- delete_queue:
    call: googleapis.cloudtasks.v2.projects.locations.queues.delete
    args:
      name: ${queue.name}
- the_end:
    return: "SUCCESS"

后续步骤

如需搜索和过滤其他 Google Cloud 产品的代码示例,请参阅 Google Cloud 示例浏览器