Cloud Scheduler quickstart

This quickstart walks you through performing the following basic operations using Cloud Scheduler:

  • Create a Cloud Scheduler job.
  • Set a recurring schedule for a job.
  • Specify a Pub/Sub topic as the job target.
  • Run a job.
  • Verify success.

Cloud Scheduler has a free tier, so running this quickstart should not result in any costs. For more information, see Pricing.

Before you begin

Use the following instructions to prepare for this quickstart. You may have already done some of these steps.

Install and configure the gcloud tool:

  1. Install and initialize the Cloud SDK

  2. Update all components:

     gcloud components update

Create a project with an App Engine app.

Or you can use an existing project, if you have one.

  1. Open a terminal on the machine where you installed the Cloud SDK and create a Cloud project:

     gcloud projects create [PROJECT_ID]

    where PROJECT_ID is the ID for the project you want to create. Project IDs must start with a lowercase letter and can have lowercase ASCII letters, digits or hyphens. They must be between 6 and 30 characters.

  2. Configure gcloud to use the project you have chosen:

     gcloud config set project [PROJECT-ID]

    where PROJECT_ID is the ID you set previously.

  3. Now create the app:

     gcloud app create [--region=REGION]

    where [REGION] is the location in which the app runs. Note that two locations, called europe-west and us-central in App Engine commands, are called, respectively, europe-west1 and us-central1 in Cloud Scheduler commands.

    You can check the region of an existing app with the command:

     gcloud app describe

    The region is listed by locationId. Your location, for example, might be shown as locationId: us-central.

    Once you set a zone for the App Engine app, you cannot change it.

Use the Google Cloud Console to enable features:

  1. Enable billing for your project

  2. Enable the Cloud Scheduler API

  3. Enable the Pub/Sub API

Use gcloud to set up Pub/Sub:

  1. Set up a Pub/Sub topic to use as a target for your cron job:

    gcloud pubsub topics create cron-topic

    This command creates a topic called 'cron-topic'. Make a note of the name because you use this later in the quickstart.

  2. Create a Pub/Sub subscription; you need this to view the results of your job.

    gcloud pubsub subscriptions create cron-sub --topic cron-topic

Create a job

  1. Visit the Cloud Scheduler page in the console:

    Cloud Scheduler

  2. Click the Create job button.

  3. Give your job a name and optionally add a description.


  4. Specify the frequency for your job, using the unix-cron format.

    * * * * *

    See Configuring Cron Job Schedules for more information. Developers familiar with App Engine Cron format can also use that.

  5. Select your timezone.

  6. In the Target field, select Pub/Sub topic from the dropdown menu and enter the topic you created earlier (cron-topic).

  7. Add a Payload string to be sent to your Pub/Sub target.


  8. Click Create.

You now have a job that sends a message to your Pub/Sub topic every minute. Let's run the job you just created.

Run your job

  1. In the Cloud Scheduler console page opened with your project, click the Run now button.

    The first job created in a project can take a few minutes to run the first time it is invoked, because of required configuration. So you might need to wait a bit.

  2. View the results under the Result column.


Congratulations! You have just viewed the results in the console of running a cron job that sends a message to Pub/Sub. Next, you'll learn how to verify that Pub/Sub actually got the message.

Verify the results in Pub/Sub

To verify that your Pub/Sub topic is receiving messages from your job:

  1. Invoke the following command:

     gcloud pubsub subscriptions pull cron-sub --limit 5
  2. View the results. You should see output that looks roughly like the following

     | DATA        | MESSAGE_ID     | ATTRIBUTES | ACK_ID                      |
     | hello cron! | 56344662920621 |            | EkwnGERJUytDCypYEU4EISE-... |
     | hello cron! | 56340561244339 |            | EkwnGERJUytDCypYEU4EISE-... |
     | hello cron! | 56340388879975 |            | EkwnGERJUytDCypYEU4EISE-... |
     | hello cron! | 56337745052761 |            | EkwnGERJUytDCypYEU4EISE...  |
     | hello cron! | 56337890896134 |            | EkwnGERJUytDCypYEU4EISE-... |

Clean up

To avoid incurring charges to your Google Cloud account for the resources used on this page, follow these steps.

Delete the Cloud Scheduler job

  1. Go to the Cloud Scheduler page in the Cloud Console.

    Go to the Scheduler page

  2. Click the checkbox next to your job.

  3. Click the Delete button at the top of the page and confirm your delete.

Delete the Pub/Sub topic

  1. Go to the Cloud Pub/Sub page in the Cloud Console.

    Go to the Pub/Sub page

  2. Click the checkbox next to your topic.

  3. Click Delete at the top of the page and confirm your delete.

Delete the project

If you created a project just for this quickstart.

  1. In the Cloud Console, go to the Manage resources page.

    Go to Manage resources

  2. In the project list, select the project that you want to delete, and then click Delete.
  3. In the dialog, type the project ID, and then click Shut down to delete the project.

What's next