워크플로 내에서 Cloud Scheduler에 액세스하는 데 사용되는 기본 제공 함수를 정의하는 Workflows 커넥터입니다.
더 살펴보기
이 코드 샘플이 포함된 자세한 문서는 다음을 참조하세요.
코드 샘플
YAML
# This workflow demonstrates how to use the Cloud Scheduler connector.
# This workflow creates a Pub/Sub topic and a subscription to the topic which is used by Cloud Scheduler
# as a notification method. The workflow then creates a scheduler job, waits for the job to finish, and pulls the notification from
# the subscription. It then deletes all resources.
# Expected successful output: "SUCCESS"
- init:
assign:
- project_id: ${sys.get_env("GOOGLE_CLOUD_PROJECT_ID")}
- location_id: "us-central1"
- job_id: "example-job-id"
- topic: "example-topic-id" # Pubsub topic used by Cloud Scheduler as a notification target.
- subscription: "example-subscription-id"
- create_topic:
call: googleapis.pubsub.v1.projects.topics.create
args:
name: ${"projects/" + project_id + "/topics/" + topic}
- create_subscription_to_topic:
call: googleapis.pubsub.v1.projects.subscriptions.create
args:
name: ${"projects/" + project_id + "/subscriptions/" + subscription}
body:
name: ${"projects/" + project_id + "/subscriptions/" + subscription}
topic: ${"projects/" + project_id + "/topics/" + topic}
- create_job:
call: googleapis.cloudscheduler.v1.projects.locations.jobs.create
args:
parent: ${"projects/" + project_id + "/locations/" + location_id}
body:
name: ${"projects/" + project_id + "/locations/" + location_id + "/jobs/" + job_id}
description: "An example job created by connector_cloudscheduler.yaml workflow to test the Cloud Scheduler connector."
schedule: "* * * * *" # Run job every minute, see https://cloud.google.com/scheduler/docs/configuring/cron-job-schedules.
pubsubTarget:
topicName: ${"projects/" + project_id + "/topics/" + topic}
attributes:
job: "finished!"
- sleep:
call: sys.sleep
args:
seconds: 100
- pull_message:
call: googleapis.pubsub.v1.projects.subscriptions.pull
args:
subscription: ${"projects/" + project_id + "/subscriptions/" + subscription}
body:
maxMessages: 1
- delete_job:
call: googleapis.cloudscheduler.v1.projects.locations.jobs.delete
args:
name: ${"projects/" + project_id + "/locations/" + location_id + "/jobs/" + job_id}
- delete_subscription:
call: googleapis.pubsub.v1.projects.subscriptions.delete
args:
subscription: ${"projects/" + project_id + "/subscriptions/" + subscription}
- delete_topic:
call: googleapis.pubsub.v1.projects.topics.delete
args:
topic: ${"projects/" + project_id + "/topics/" + topic}
- the_end:
return: "SUCCESS"
다음 단계
다른 Google Cloud 제품의 코드 샘플을 검색하고 필터링하려면 Google Cloud 샘플 브라우저를 참조하세요.