Cloud Scheduler API Connector Overview

The Workflows connector defines the built-in functions that can be used to access other Google Cloud products within a workflow.

This page provides an overview of the individual connector. There is no need to import or load connector libraries in a workflow—connectors work out of the box when used in a call step.

Cloud Scheduler API

Creates and manages jobs run on a regular recurring schedule. To learn more, see the Cloud Scheduler API documentation.

Cloud Scheduler connector sample

YAML

# This workflow demonstrates how to use the Cloud Scheduler connector:
# Create a Pub/Sub topic and subscription for notifications
# Create a Cloud Scheduler job that runs every minute and publishes
# a message to the Pub/Sub topic when finished
# Retrieve message from the subscription and then delete all resources
# Expected 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"
      - 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 Workflows to test the Cloud Scheduler connector."
        schedule: "* * * * *"  # runs job every minute
        pubsubTarget:
          topicName: ${"projects/" + project_id + "/topics/" + topic}
          attributes:
            job: "finished!"
- sleep:
    call: sys.sleep
    args:
      seconds: 100  # sleeps for 100 seconds to allow job to run
- 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"

JSON

[
  {
    "init": {
      "assign": [
        {
          "project_id": "${sys.get_env(\"GOOGLE_CLOUD_PROJECT_ID\")}"
        },
        {
          "location_id": "us-central1"
        },
        {
          "job_id": "example-job-id"
        },
        {
          "topic": "example-topic-id"
        },
        {
          "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 Workflows to test the Cloud Scheduler connector.",
          "schedule": "* * * * *",
          "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"
    }
  }
]

Module: googleapis.cloudscheduler.v1.projects.locations

Functions
get Gets information about a location.
list Lists information about the supported locations for this service.

Module: googleapis.cloudscheduler.v1.projects.locations.jobs

Functions
create Creates a job.
delete Deletes a job.
get Gets a job.
list Lists jobs.
patch Updates a job. If successful, the updated Job is returned. If the job does not exist, NOT_FOUND is returned. If UpdateJob does not successfully return, it is possible for the job to be in an Job.State.UPDATE_FAILED state. A job in this state may not be executed. If this happens, retry the UpdateJob request until a successful response is received.
pause Pauses a job. If a job is paused then the system will stop executing the job until it is re-enabled via ResumeJob. The state of the job is stored in state; if paused it will be set to Job.State.PAUSED. A job must be in Job.State.ENABLED to be paused.
resume Resume a job. This method reenables a job after it has been Job.State.PAUSED. The state of a job is stored in Job.state; after calling this method it will be set to Job.State.ENABLED. A job must be in Job.State.PAUSED to be resumed.
run Forces a job to run now. When this method is called, Cloud Scheduler will dispatch the job, even if the job is already running.

Module: googleapis.cloudscheduler.v1beta1.projects.locations

Functions
get Gets information about a location.
list Lists information about the supported locations for this service.

Module: googleapis.cloudscheduler.v1beta1.projects.locations.jobs

Functions
create Creates a job.
delete Deletes a job.
get Gets a job.
list Lists jobs.
patch Updates a job. If successful, the updated Job is returned. If the job does not exist, NOT_FOUND is returned. If UpdateJob does not successfully return, it is possible for the job to be in an Job.State.UPDATE_FAILED state. A job in this state may not be executed. If this happens, retry the UpdateJob request until a successful response is received.
pause Pauses a job. If a job is paused then the system will stop executing the job until it is re-enabled via ResumeJob. The state of the job is stored in state; if paused it will be set to Job.State.PAUSED. A job must be in Job.State.ENABLED to be paused.
resume Resume a job. This method reenables a job after it has been Job.State.PAUSED. The state of a job is stored in Job.state; after calling this method it will be set to Job.State.ENABLED. A job must be in Job.State.PAUSED to be resumed.
run Forces a job to run now. When this method is called, Cloud Scheduler will dispatch the job, even if the job is already running.