Edit on GitHub
Report issue
Page history

Schedule periodic jobs with Cloud Scheduler

Author(s): @timtech4u ,   Published: 2019-12-03

Google Cloud Community tutorials submitted from the community do not represent official Google Cloud product documentation.


Automating tasks that re-occur is definitely at the heart of every software developer. Google Cloud provides Cloud Scheduler, a tool that allows users to schedule jobs with the conventional unix-cron format.

Cloud Scheduler can be referred to as a cron-job-as-a-service tool. It is fully managed by Google Cloud, so you don't need to manage the scheduler's underlying infrastructure.

Cloud Scheduler can be used for multiple use cases, such as making requests to an HTTP/S endpoint, invoking a Pub/Sub topic, making database updates and push notifications, triggering CI/CD pipelines, scheduling tasks such as image uploads and sending email, and even invoking Cloud Functions.

Objective

In this tutorial, you use Cloud Scheduler to make simple requests to an HTTP endpoint.

Before you begin

  1. Set up a Google Cloud account and project.

  2. Enable Cloud Scheduler.

  3. Copy the URL of the HTTP endpoint that you would like to make requests to.

Get the sample code

The author of this tutorial built a tool that periodically makes request to Cloud Run services to prevent them from having cold starts. Get the code from GitHub.

Setting up Cloud Scheduler

  1. Visit Cloud Scheduler and click Create Job

  2. Enter the job name.

  3. Frequency: Enter every 24 hours, or enter another value to suit your use case.

  4. Target: Select HTTP.

  5. URL: Enter the application or function URL.

  6. HTTP Method: Select GET.

  7. Click Create.

Next steps

If you face problems with HTTP headers or other issues while using Cloud Scheduler, check out John Hanley's answers on Stack Overflow..

Cloud Scheduler can also be used with Firebase Cloud Functions, which automatically configures Cloud Scheduler, along with a Pub/Sub topic that invokes the function that you define using the Cloud Functions for Firebase SDK. (Read more.)

Stackdriver integrates with Cloud Scheduler, providing powerful logging for greater transparency into job execution and performance.

Pricing

Cloud Scheduler is simple and pay-for-use. You pay for the number of jobs you use each month. Google Cloud allows you create three free jobs per month, and you pay for others at $0.10/job/month.

Resources

If you want to learn more about Cloud Scheduler, check out the following resources:

Thanks for reading through! Let me know if I missed anything, if something didn’t work out quite right for you, or if this guide was helpful.

Submit a tutorial

Share step-by-step guides

Submit a tutorial

Request a tutorial

Ask for community help

Submit a request

View tutorials

Search Google Cloud tutorials

View tutorials

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see our Site Policies. Java is a registered trademark of Oracle and/or its affiliates.