Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Table of contents
1.
Introduction
2.
Cloud Scheduler
3.
Types of Cloud Scheduler
4.
Setting up the Environment
4.1.
Install and Configure the gcloud CLI
4.2.
Creating a Project using gcloud
4.3.
Create an App Engine app using gcloud when suitable.
5.
Creation of Cron Jobs
5.1.
Creating a Job
5.2.
Editing a Cron Job
5.3.
Pause a Cron Job
5.4.
Resume a Cron Job
5.5.
 Delete a Cron Job
6.
Configure Cron Jobs Schedules
7.
Limiting Cron Job Target Type
8.
Viewing Logs using Cloud Scheduler
9.
Authentication with HTTP targets
10.
Establishing an authentication-based scheduler job
11.
Manually assign the Cloud Scheduler Service Agent role to your Cloud Scheduler service account.
12.
Features of Cloud Scheduler
13.
Advantages of Cloud Scheduler
14.
Disadvantages of Cloud Scheduler
15.
Frequently Asked Questions
15.1.
What is Google App Engine?
15.2.
What is Cloud Computing?
15.3.
What is Google Scheduler Service?
16.
Conclusion
Last Updated: Mar 27, 2024
Easy

Overview of Cloud Scheduler

Author Ayush Mishra
1 upvote
Leveraging ChatGPT - GenAI as a Microsoft Data Expert
Speaker
Prerita Agarwal
Data Specialist @
23 Jul, 2024 @ 01:30 PM

Introduction

Google Cloud is a group of open Cloud Computing services provided by Google. The platform has many hosted services for computing, storing, and creating applications powered by Google hardware. 

It consists of various online services that can assist businesses in going digital. Many company IT experts can access Google Cloud services via a dedicated network connection or the open internet.
 

Google Cloud Platform

In this blog, we will discuss the Overview of Cloud Scheduler, which allows us to conduct specific tasks regularly. Let's get going!

Cloud Scheduler

The Cloud Scheduler allows us to conduct specific tasks on a regular basis. In the traditional approach, a constantly running service often houses a cron job. However, creating recurring tasks is simple by using Cloud Scheduler.

The diagramclocd scheduler working phases

It is a cron job scheduler that can handle various jobs, including batch workloads and big data. An enterprise-grade cron task scheduler that is completely managed is called Cloud Scheduler. 

Cloud Scheduler can be used to schedule batch workloads, big data operations, cloud infrastructure operations, and more.

Get the tech career you deserve, faster!
Connect with our expert counsellors to understand how to hack your way to success
User rating 4.7/5
1:1 doubt support
95% placement record
Akash Pal
Senior Software Engineer
326% Hike After Job Bootcamp
Himanshu Gusain
Programmer Analyst
32 LPA After Job Bootcamp
After Job
Bootcamp

Types of Cloud Scheduler

There are three ways the Cloud Scheduler can create events.

1. App Engine: Use this to carry out tasks from the App engine.

2. HTTP: It is more adaptable and uses the HTTP protocol to submit requests. So long as a service offers HTTP protocol, it can be any service, including those provided by third parties or internal servers (like REST API).

3. Pub/Sub: This can also be quite useful for using subscribers to start events. This allows us to trigger numerous subscribers, who can be anything, with a single scheduler event.

Setting up the Environment

In this part of “Overview of Cloud Scheduler,” we will look at the steps to configure Cloud Scheduler. On your computer, some of these tools might already be installed.

Install and Configure the gcloud CLI

Step1.Install and initialize the gcloud CLI
 

Step 2. Add the gcloud components for products:

gcloud components install

 

Step 3. Update all components

gcloud components update

 

Creating a Project using gcloud

Alternatively, if you already have a project, you can use it.

Step 1. Create a Cloud project by opening a terminal on the computer where you installed the gcloud CLI:

gcloud projects create ID_PROJECT

where, ID_PROJECT is the ID for the project you want to create. Project IDs can be lowercase ASCII characters, numerals, or hyphens and must begin with a lowercase letter. They must have a character count of six to thirty.

 

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

gcloud config set project ID_PROJECT

 where, ID_PROJECT is the ID you set previously.

 

Create an App Engine app using gcloud when suitable.

Your project must contain an App Engine app if you plan to use an App Engine HTTP target. The handler and the Cloud Scheduler service are housed within this app. You should choose an HTTP target if you want an App Engine handler that is not part of your project. In this situation, your project does not require an App Engine app.

gcloud app create [--region=REGION

where, REGION denotes the area where the app is installed. In App Engine commands, two locations are identified as europe-west and us-central, respectively. In Cloud Scheduler commands, these locations are identified as europe-west1 and us-central1, respectively.
 

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

LocationId is used to list the region. For instance, locationId: us-central might be displayed for your location.

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

Enabling features using the Google Cloud console:

  1. Enable billing for your project
  2. Enable the Cloud Scheduler API

Your project now supports Cloud Scheduler.

Creation of Cron Jobs

In this "Overview of Cloud Scheduler," we will look at the steps to create the Cron Jobs. They are units of work scheduled by Cloud Scheduler. They are sent to targets on a reoccurring schedule, also known as the job interval or frequency.

Creating a Job

Steps to create a Cron Job are:-

  • Go to Cloud Scheduler in the console.
     
  • Choose to Create a Job.
     
  • Give the task a name that is specific to the project in the Name box. You can use a job name again in a project after deleting the job that it is linked with.
     
  • Select a region from the Region list.
     
  • You must select the same region as your App Engine app if you're utilizing an App Engine HTTP target. 
     
  • Provide a brief job description if desired, perhaps including a recap of the duties. In the console, this description is displayed next to the job name.
     
  • Use a configuration string to specify how often the job should run.
     
  • Select the timezone to be used for the job schedule from the Timezone list.
     
  • Click the Continue button.
     
  • Set the Target type:-   HTTP,  Pub/Sub,  or App Engine HTTP.
     
  • Click the Continue button.
     
  • Click Configure optional parameters to configure any retry behavior. Use a sequence of decimal non-negative numbers with the following unit suffixes to express the duration
    • h - hour
    • m - minute
    • s - second
    • ms - millisecond
    • us - microsecond
    • ns - nanosecond
       
  • Configure a deadline for job attempts for HTTP and App Engine HTTP targets, if desired. If the request handler does not answer within this time frame, the request is canceled, and the attempt is reported as unsuccessful. Cloud Scheduler retries the job based on the retry configuration.
     
  • Click Create to start and save the job.

The job will now execute on the chosen schedule.

Editing a Cron Job

In this “Overview of Cloud Scheduler,” we will look at the steps to edit the Cron Jobs.

  • Navigate to Cloud Scheduler in the console.
  • Choose the job to edit.
  • Select Edit.
  • When creating a job, follow the steps to specify the schedule, arrange the execution, and select optional settings.

Pause a Cron Job

In this “Overview of Cloud Scheduler,” we will look at the steps to pause the Cron Jobs.

  • Navigate to Cloud Scheduler in the console.
  • Choose the job to pause.
  • Press the Pause button.

Resume a Cron Job

In this “Overview of Cloud Scheduler,” we will look at the steps to resume the Cron Jobs.

  • Navigate to Cloud Scheduler in the console.
  • Choose the job to resume.
  • Press the Resume button

 Delete a Cron Job

In this “Overview of Cloud Scheduler,” we will look at the steps to delete the Cron Jobs.

  • Navigate to Cloud Scheduler in the console.
  • Choose the job to delete.
  • Press the Delete button

Configure Cron Jobs Schedules

Cron tasks are run at regular intervals. You can program your job to run numerous times per day or on specified days and months.

The Unix-cron string format (* * * * *) is used to create a schedule, which is a series of five fields in a line that indicate when the job should be executed.

Google Cloud CLI or the cloud scheduler is used to set your schedule.

The time fields have the following format and allowable values, and they must be entered in the following order:

time fields and valid value format.

Special Character to represent the Unix-Crox string format is:

  • An asterisk (*) in a field always means "first-last."
     
  • Ranges are two numbers separated by a hyphen (-), and the selected range is inclusive.
     
  • Following a range with /NUMBER indicates skips of the number's value through the range. For example, in the Hour parameter, both 0-23/2 and */2 can be used to specify execution every two hours.
     
  • A list is a collection of integers (or ranges) separated by commas (,). For example, 1,2,5,6 in the Month field indicates an execution on the first, second, fifth, and sixth days of the month.

Limiting Cron Job Target Type

In some cases, limiting the job target type may be beneficial. To accomplish this, administrators with the Organization Policy Administrator role can set up a policy to limit the types of job targets that can be generated in their organization (HTTP, Pub/Sub, and/or App Engine HTTP).

In the “Overview of Cloud Scheduler,” we will look at the steps to limit job target type:-

  • Visit the IAM & Admin section's Organization policies page.
     
  • Select the resource (organization or project) to which you want to apply the constraint from the top left option.
     
  • Choose Allowed job target categories from the list of Organization Policies.
     
  • Click the Edit button on the policy page.
     
  • Select Add Rule from the Rules menu.
    1. For Policy values, select Custom.
    2. Choose to Allow for Policy Type.
    3. Allowlist the type (PUBSUB, HTTP, or APPENGINE).
    4. To add numerous job kinds, click on New Policy Value.
    5. Save for the purpose of enforcing the policy.                

Viewing Logs using Cloud Scheduler

In this  “Overview of Cloud Scheduler,” we will look at how Cloud Scheduler publishes logs at the start and end of execution.

Steps to view logs:-

Step 1: Open the Google Cloud Console and navigate to the Cloud Scheduler page:

Step 2: Locate the desired job and click the View link in the Logs column. This will take you to the Cloud Logging Logs Explorer page.

Step 3: View the logs in detail.

Authentication with HTTP targets

In this  “Overview of Cloud Scheduler,” we will look at authentication with HTTP targets. Cloud Scheduler can call HTTP targets If you have configured a related service account with the proper credentials.

Steps to set the service account:

Step 1. Choose an existing service account or make a new service account just for this call from Cloud Scheduler to your HTTP target.

Step 2. The project in which the Cloud Scheduler jobs are created must be the same project as the service account. The customer service account is this.

Step 3. Give the required IAM role to your client service account in order to update it if your target is a Google Cloud member. There are many roles needed for each Google Cloud service.

Step 4. The Cloud Run Invoker role, for instance, must be added for Cloud Run, and so forth. The receiving service checks the created token automatically. If your target is not a Google Cloud service, the receiving service will need to manually validate the token.

Step 5. Additionally, your project must have the default Cloud Scheduler service account and grant it the Cloud Scheduler Service Agent role. This is done so that it may create header tokens on your behalf to authenticate with your target on behalf of your client service account.

Step 6. Unless you activated the Cloud Scheduler API before March 19, 2019, in which case you must manually add the role, the Cloud Scheduler service account with this role granted is created when you enable the Cloud Scheduler API.

Establishing an authentication-based scheduler job

You must provide two pieces of information in your create-job request in order to create a job that requires authentication:

1. The token type you select

2. The email address associated with the customer service account

 

Steps to establish an authentication-based scheduler job:

Step 1. Provide the frequency.

Step 2. Set the target type to HTTP.

Step 3. Include the URL and method.

Step 4. From the Auth header menu, select the token type.

Step 5. In the Service account text box, enter the client service account email address.

Manually assign the Cloud Scheduler Service Agent role to your Cloud Scheduler service account.

Steps to assign cloud scheduler service agent role to cloud scheduler service account:-

Step 1. On the Google Cloud Project Settings Page, look for your project's project number.

Step 2. Make a note of the number.

Step 3. Navigate to the IAM Admin Console page.

Step 4. Select Add. The Add Members window appears.

Step 5. Add an email address in the format: to the New members' dialogue box.

service-[project-number]@gcp-sa-cloudscheduler.iam.gserviceaccount.com

 

Step 6. Select Service Management -> Cloud Scheduler Service Agent from the Select a role drop-down menu.

Step 7. Save the file.

Features of Cloud Scheduler

→ Full-service management.

→ Cron job management with a straightforward UI and command line.

→ Support for Cloud Pub/Sub, App Engine, and arbitrary HTTP endpoints.

→ Retry policy that is programmable.

→ Assurance of delivery, at least once, to your work targets.

→ Cron jobs with enterprise-grade reliability.

→ Acceptance of the Unix cron format.

→ Strong logging.

Advantages of Cloud Scheduler

→ Integration of cloud logging to provide visibility into job execution and performance.

→ You don't have to learn crontab.

→ Set your job up to retry in case of error or failure.

→ Manage every automation task you have in one location.

→ Automate the time-consuming tasks involved in operating cloud infrastructure.

Disadvantages of Cloud Scheduler

→ It only permits a 30-minute worker runtime. Batch procedures are assumed to have failed if they take longer than that.

→ This HTTP endpoint ought to be open to the public. Although we can add IAM or OAuth authentication, it is still open to the public and exposed to outside threats. Additionally, the public indicates that data between the batch process and Cloud Scheduler travels over a public network.

Frequently Asked Questions

What is Google App Engine?

Google App Engine provides scalable services for companies and web application developers as a part of Platform as a Service. The developers can use this to create and deploy a fully managed platform and scale it as necessary.

What is Cloud Computing?

Computing power on the cloud at all times is known as cloud computing. Its preferred delivery mechanism is the internet. This technology's services are available anywhere and are not region-specific.

What is Google Scheduler Service?

Almost any work, including batch jobs, big data activities, cloud infrastructure operations, and more, can be scheduled using Google Scheduler Service.

Conclusion

Congratulations on finishing the blog! We have discussed the Overview of the cloud scheduler. We further look at the features, setting up of the environment, advantages, and disadvantages of cloud scheduler.

If you want to explore more blogs on this topic, please follow these blogs especially curated for readers like you- Cloud Computing, Cloud Computing Technologies, Cloud Server, and Cloud Computing Infrastructure.

Please refer to our guided pathways on Code studio to learn more about DSACompetitive ProgrammingJavaScriptSystem Design, etc. Enroll in our courses, and use the accessible sample exams and questions as a guide. For placement preparations, look at the interview experiences and interview package.

Please do upvote our blogs if you find them helpful and informative!

Happy learning!

Live masterclass