### Install Go Client Library Source: https://docs.cloud.google.com/scheduler/docs/reference/libraries?hl=es Use the go get command to fetch the Cloud Scheduler module. ```bash go get cloud.google.com/go/scheduler/apiv1 ``` -------------------------------- ### Install PHP Client Library Source: https://docs.cloud.google.com/scheduler/docs/reference/libraries?hl=es Use composer to install the Cloud Scheduler library. ```bash composer require google/cloud-scheduler ``` -------------------------------- ### Install Ruby Client Library Source: https://docs.cloud.google.com/scheduler/docs/reference/libraries?hl=es Use gem to install the Cloud Scheduler library. ```bash gem install google-cloud-scheduler ``` -------------------------------- ### Install Python Client Library Source: https://docs.cloud.google.com/scheduler/docs/reference/libraries?hl=es Install the library within a virtual environment for Mac/Linux or Windows. ```bash pip install virtualenv virtualenv YOUR_ENV source YOUR_ENV/bin/activate YOUR_ENV/bin/pip install google-cloud-scheduler ``` ```bash pip install virtualenv virtualenv YOUR_ENV YOUR_ENV\Scripts\activate YOUR_ENV\Scripts\pip.exe install google-cloud-scheduler ``` -------------------------------- ### Install Python Cloud Scheduler Library Source: https://docs.cloud.google.com/scheduler/docs/reference/libraries?hl=es-419 Set up a virtual environment and install the Cloud Scheduler library using pip. ```bash pip install virtualenv virtualenv YOUR_ENV source YOUR_ENV/bin/activate YOUR_ENV/bin/pip install google-cloud-scheduler ``` ```bash pip install virtualenv virtualenv YOUR_ENV YOUR_ENV\Scripts\activate YOUR_ENV\Scripts\pip.exe install google-cloud-scheduler ``` -------------------------------- ### Install C# Client Library Source: https://docs.cloud.google.com/scheduler/docs/reference/libraries?hl=es Use NuGet to install the Cloud Scheduler package for C#. ```bash Install-Package Google.Cloud.Scheduler.V1 ``` -------------------------------- ### Install Node.js Client Library Source: https://docs.cloud.google.com/scheduler/docs/reference/libraries?hl=es Use npm to install the Cloud Scheduler package. ```bash npm install @google-cloud/scheduler ``` -------------------------------- ### Install Python Client Library for Cloud Scheduler (Windows) Source: https://docs.cloud.google.com/scheduler/docs/reference/libraries?hl=it Install the Python client library for Cloud Scheduler within a virtual environment on Windows. This addresses dependency and versioning issues. ```bash pip install virtualenv virtualenv YOUR_ENV YOUR_ENV\Scripts\activate YOUR_ENV\Scripts\pip.exe install google-cloud-scheduler ``` -------------------------------- ### Location Labels Example Source: https://docs.cloud.google.com/scheduler/docs/reference/rest/v1/projects.locations An example of the labels map for a location resource. ```json {"cloud.googleapis.com/region": "us-east1"} ``` -------------------------------- ### Implement Start Instance Cloud Function Source: https://docs.cloud.google.com/scheduler/docs/start-and-stop-compute-engine-instances-on-a-schedule Node.js function to start Compute Engine instances filtered by labels provided in a Pub/Sub message. ```javascript const compute = require('@google-cloud/compute'); const instancesClient = new compute.InstancesClient(); const operationsClient = new compute.ZoneOperationsClient(); async function waitForOperation(projectId, operation) { while (operation.status !== 'DONE') { [operation] = await operationsClient.wait({ operation: operation.name, project: projectId, zone: operation.zone.split('/').pop(), }); } } /** * Starts Compute Engine instances. * * Expects a PubSub message with JSON-formatted event data containing the * following attributes: * zone - the GCP zone the instances are located in. * label - the label of instances to start. * * @param {!object} event Cloud Function PubSub message event. * @param {!object} callback Cloud Function PubSub callback indicating * completion. */ exports.startInstancePubSub = async (event, context, callback) => { try { const project = await instancesClient.getProjectId(); const payload = _validatePayload(event); const options = { filter: `labels.${payload.label}`, project, zone: payload.zone, }; const [instances] = await instancesClient.list(options); await Promise.all( instances.map(async instance => { const [response] = await instancesClient.start({ project, zone: payload.zone, instance: instance.name, }); return waitForOperation(project, response.latestResponse); }) ); // Operation complete. Instance successfully started. const message = 'Successfully started instance(s)'; console.log(message); callback(null, message); } catch (err) { console.log(err); callback(err); } }; /** * Validates that a request payload contains the expected fields. * * @param {!object} payload the request payload to validate. * @return {!object} the payload object. */ const _validatePayload = event => { let payload; try { payload = JSON.parse(Buffer.from(event.data, 'base64').toString()); } catch (err) { throw new Error('Invalid Pub/Sub message: ' + err); } if (!payload.zone) { throw new Error("Attribute 'zone' missing from payload"); } else if (!payload.label) { throw new Error("Attribute 'label' missing from payload"); } return payload; }; ``` -------------------------------- ### Example of Details Field Source: https://docs.cloud.google.com/scheduler/docs/reference/rest/Shared.Types/Status?hl=ja An example showing how to include an arbitrary type in the details field using the @type URI. ```json { "id": 1234, "@type": "types.example.com/standard/id" } ``` -------------------------------- ### Install Python Client Library for Cloud Scheduler (Mac/Linux) Source: https://docs.cloud.google.com/scheduler/docs/reference/libraries?hl=it Install the Python client library for Cloud Scheduler within a virtual environment on Mac or Linux. This addresses dependency and versioning issues. ```bash pip install virtualenv virtualenv YOUR_ENV source YOUR_ENV/bin/activate YOUR_ENV/bin/pip install google-cloud-scheduler ``` -------------------------------- ### Example Pub/Sub message output Source: https://docs.cloud.google.com/scheduler/docs/schedule-run-cron-job-gcloud This is an example of the output you might see when pulling messages from a Pub/Sub subscription, indicating a successful job execution. ```text DATA: Hello world! MESSAGE_ID: 5028933846601543 ORDERING_KEY: ATTRIBUTES: DELIVERY_ATTEMPT: ACK_ID: RFAGFixdRkhRNxkIaFEOT14jPzUgKEUQAgVPAihdeTFXLkFacGhRDRlyfWB9[...] ``` -------------------------------- ### Groc Time Specification Examples Source: https://docs.cloud.google.com/scheduler/docs/configuring/cron-job-schedules These examples demonstrate the groc format for specifying recurring job schedules, which is more human-readable than cron expressions. Use this format with the gcloud CLI or Cloud Scheduler API. ```groc first sunday of month 12:00 ``` ```groc 2nd,3rd tue,wed,thu of feb,aug 13:50 ``` ```groc every wed of december 00:00 ``` ```groc 1st friday of quarter 9:00 ``` ```groc second,4th tue,thursday of 3rd month of quarter 18:30 ``` ```groc 1,3,4,7,11,18,29 of jan,jul 12:34 ``` ```groc 03 of month 12:34 ``` ```groc every day 09:00 ``` ```groc every sun,tue,thu 9:00 ``` ```groc every 48 hours ``` ```groc every 5 minutes ``` ```groc every 60 minutes on mon,wed ``` ```groc every minute ``` -------------------------------- ### Location Labels Example Source: https://docs.cloud.google.com/scheduler/docs/reference/rest/v1/projects.locations?hl=ja An example of how cross-service attributes for a location are represented using labels. This specific example shows a region label. ```json { "cloud.googleapis.com/region": "us-east1" } ``` -------------------------------- ### Retrieve and Navigate Sample Code Source: https://docs.cloud.google.com/scheduler/docs/start-and-stop-compute-engine-instances-on-a-schedule Commands to clone the repository and navigate to the relevant directory. ```bash git clone https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git ``` ```bash cd nodejs-docs-samples/functions/scheduleinstance/ ``` -------------------------------- ### Get Operation Source: https://docs.cloud.google.com/scheduler/docs/reference/rest?hl=de Gets the latest state of a long-running operation. ```APIDOC ## GET /v1/{name=projects/*/locations/*/operations/*} ### Description Gets the latest state of a long-running operation. ### Method GET ### Endpoint `/v1/{name=projects/*/locations/*/operations/*}` ### Parameters #### Path Parameters - **name** (string) - Required - The name of the operation resource to be retrieved. ``` -------------------------------- ### Verify Instance Status is RUNNING Source: https://docs.cloud.google.com/scheduler/docs/start-and-stop-compute-engine-instances-on-a-schedule This output indicates that the VM instance has been successfully started. ```text status: RUNNING ``` -------------------------------- ### GET /operations/{name} Source: https://docs.cloud.google.com/scheduler/docs/reference/rpc/google.longrunning Gets the latest state of a long-running operation. ```APIDOC ## GET /operations/{name} ### Description Gets the latest state of a long-running operation. Clients can use this method to poll the operation result. ### Method GET ### Endpoint /operations/{name} ### Parameters #### Path Parameters - **name** (string) - Required - The name of the operation resource. ``` -------------------------------- ### Get Long-Running Operation Source: https://docs.cloud.google.com/scheduler/docs/reference/rest?hl=ko Gets the latest state of a long-running operation. ```APIDOC ## GET /v1/{name=projects/*/locations/*/operations/*} ### Description Gets the latest state of a long-running operation. ### Method GET ### Endpoint `/v1/{name=projects/*/locations/*/operations/*}` ### Parameters #### Path Parameters - **name** (string) - Required - The name of the operation resource to get. ``` -------------------------------- ### Verify instance status after starting Source: https://docs.cloud.google.com/scheduler/docs/start-and-stop-compute-engine-instances-on-a-schedule Use the gcloud CLI to describe a VM instance and filter for its status, confirming it is running. ```bash gcloud compute instances describe dev-instance \ --zone us-west1-b \ | grep status ``` ```text status: RUNNING ``` -------------------------------- ### GET /v1/{name} Source: https://docs.cloud.google.com/scheduler/docs/reference/rest?hl=fr Gets the latest state of a long-running operation. ```APIDOC ## GET /v1/{name=projects/*/locations/*/operations/*} ### Description Gets the latest state of a long-running operation. ### Method GET ### Endpoint /v1/{name=projects/*/locations/*/operations/*} ### Parameters #### Path Parameters - **name** (string) - Required - The name of the operation resource. ``` -------------------------------- ### GET /locations/{location} Source: https://docs.cloud.google.com/scheduler/docs/reference/rest/v1/projects.locations?hl=zh-cn Gets information about a specific Cloud Scheduler location. ```APIDOC ## GET /locations/{location} ### Description Gets information about a location. ### Method GET ### Endpoint `/locations/{location}` ### Parameters #### Path Parameters - **location** (string) - Required - The name of the location to retrieve. ``` -------------------------------- ### Create Pub/Sub Message for Instance Startup Source: https://docs.cloud.google.com/scheduler/docs/start-and-stop-compute-engine-instances-on-a-schedule This JSON message is sent to the 'start-instance-event' Pub/Sub topic to initiate instance startup. Specify the zone and labels for the target instance. ```json {"zone":"us-west1-b","label":"env=dev"} ``` -------------------------------- ### GET /v1/{name=projects/*/locations/*/operations/*} Source: https://docs.cloud.google.com/scheduler/docs/reference/rest?hl=pt Gets the latest state of a long-running operation. ```APIDOC ## GET /v1/{name=projects/*/locations/*/operations/*} ### Description Gets the latest state of a long-running operation. ### Method GET ### Endpoint `/v1/{name=projects/*/locations/*/operations/*}` ### Parameters #### Path Parameters - **name** (string) - Required - The name of the operation resource. ### Request Body This method does not take a request body. ``` -------------------------------- ### Create and Select Google Cloud Project Source: https://docs.cloud.google.com/scheduler/docs/schedule-run-cron-job-terraform Commands to create a new project and set it as the active project in the CLI. ```bash gcloud projects create PROJECT_ID ``` ```bash gcloud config set project PROJECT_ID ``` -------------------------------- ### Iniciar instância via Pub/Sub Source: https://docs.cloud.google.com/scheduler/docs/start-and-stop-compute-engine-instances-on-a-schedule?hl=pt-br Invoca a função de inicialização passando os dados da instância codificados em base64. ```bash gcloud functions call startInstancePubSub \ --data '{"data":"eyJ6b25lIjoidXMtd2VzdDEtYiIsICJsYWJlbCI6ImVudj1kZXYifQo="}' ``` -------------------------------- ### Configure Authentication Source: https://docs.cloud.google.com/scheduler/docs/reference/libraries?hl=es Initialize the Google Cloud CLI and set up Application Default Credentials for local development. ```bash gcloud init ``` ```bash gcloud auth application-default login ``` -------------------------------- ### Location Labels Example Source: https://docs.cloud.google.com/scheduler/docs/reference/rest/v1/projects.locations?hl=fr An example of how labels can be used for a location, typically to denote service-specific attributes like the region. ```json { "cloud.googleapis.com/region": "us-east1" } ``` -------------------------------- ### Deploy Cloud Functions Source: https://docs.cloud.google.com/scheduler/docs/start-and-stop-compute-engine-instances-on-a-schedule Commands to deploy the start and stop functions to Google Cloud. ```bash gcloud functions deploy startInstancePubSub \ --trigger-topic start-instance-event \ --runtime nodejs18 \ --allow-unauthenticated ``` ```bash gcloud functions deploy stopInstancePubSub \ --trigger-topic stop-instance-event \ --runtime nodejs18 \ --allow-unauthenticated ``` -------------------------------- ### Create a Google Cloud Project Source: https://docs.cloud.google.com/scheduler/docs/schedule-run-cron-job-gcloud Use this command to create a new Google Cloud project. Replace PROJECT_ID with your desired project name. ```bash gcloud projects create PROJECT_ID ``` -------------------------------- ### Initialize Google Cloud CLI Source: https://docs.cloud.google.com/scheduler/docs/authentication Initialize the Google Cloud CLI. This command is used to set up your local environment for authentication. ```bash gcloud init ``` -------------------------------- ### Base64 encoded string example Source: https://docs.cloud.google.com/scheduler/docs/start-and-stop-compute-engine-instances-on-a-schedule?hl=pt-br This is an example of a base64 encoded string, typically used as data payload for Cloud Functions when specific instance parameters need to be passed. ```text eyJ6b25lIjoidXMtd2VzdDEtYiIsICJsYWJlbCI6ImVudj1kZXYifQo= ``` -------------------------------- ### Initialize Terraform Directory Source: https://docs.cloud.google.com/scheduler/docs/schedule-run-cron-job-terraform Commands to create a working directory and file for Terraform configuration. ```bash mkdir terraform ``` ```bash cd terraform ``` ```bash nano main.tf ``` -------------------------------- ### Create Compute Engine Instance with Service Account Source: https://docs.cloud.google.com/scheduler/docs/authentication Create a Compute Engine instance and attach a specific service account to it. This allows the instance to authenticate using the service account's credentials. ```bash gcloud compute instances create INSTANCE_NAME --zone=ZONE --service-account=SERVICE_ACCOUNT_EMAIL ``` -------------------------------- ### Create Cloud Scheduler Job for Instance Startup using gcloud Source: https://docs.cloud.google.com/scheduler/docs/start-and-stop-compute-engine-instances-on-a-schedule Use this gcloud command to create a Cloud Scheduler job that publishes a message to a Pub/Sub topic for starting instances on a schedule. ```bash gcloud scheduler jobs create pubsub startup-dev-instances \ --schedule '0 9 * * 1-5' \ --topic start-instance-event \ --message-body '{"zone":"us-west1-b", "label":"env=dev"}' \ --time-zone 'America/Los_Angeles' \ --location us-central1 ``` -------------------------------- ### Manually Run Cloud Scheduler Job to Start Instance Source: https://docs.cloud.google.com/scheduler/docs/start-and-stop-compute-engine-instances-on-a-schedule This command manually triggers a Cloud Scheduler job to start a specific instance. Ensure the job name matches the one created. ```bash gcloud beta scheduler jobs run startup-dev-instances ``` -------------------------------- ### Create Pub/Sub Topics Source: https://docs.cloud.google.com/scheduler/docs/start-and-stop-compute-engine-instances-on-a-schedule Commands to create the Pub/Sub topics required for triggering instance management functions. ```bash gcloud pubsub topics create start-instance-event ``` ```bash gcloud pubsub topics create stop-instance-event ``` -------------------------------- ### GET /GetLocation Source: https://docs.cloud.google.com/scheduler/docs/reference/rpc/google.cloud.location?hl=zh-cn Retrieves information about a specific location. ```APIDOC ## GET GetLocation ### Description Gets information about a location. ### Method GET ### Parameters #### Request Body - **name** (string) - Required - Resource name for the location. ### Response #### Success Response (200) - **Location** (object) - Returns the location resource. ``` -------------------------------- ### Get Job API Source: https://docs.cloud.google.com/scheduler/docs/reference/rpc/google.cloud.scheduler.v1beta1?hl=fr Retrieves a job by its name. ```APIDOC ## GET /api/jobs/{name} ### Description Retrieves a job. ### Method GET ### Endpoint `/api/jobs/{name}` ### Parameters #### Path Parameters - **name** (string) - Required - The job name. For example: `projects/PROJECT_ID/locations/LOCATION_ID/jobs/JOB_ID`. Authorization requires the following IAM permission on the specified resource `name`: `cloudscheduler.jobs.get`. ``` -------------------------------- ### Deploy Terraform Resources Source: https://docs.cloud.google.com/scheduler/docs/schedule-run-cron-job-terraform Commands to initialize, plan, and apply Terraform configurations. ```bash terraform init ``` ```bash terraform plan ``` ```bash terraform apply ``` -------------------------------- ### GET /jobs/{name} Source: https://docs.cloud.google.com/scheduler/docs/reference/rpc/google.cloud.scheduler.v1?hl=pt Retrieves a job specified by its name. ```APIDOC ## GET /jobs/{name} ### Description Retrieves a job specified by its name. ### Method GET ### Endpoint `/jobs/{name}` ### Parameters #### Path Parameters - **name** (string) - Required - The job name. For example: `projects/PROJECT_ID/locations/LOCATION_ID/jobs/JOB_ID`. Authorization requires the following IAM permission on the specified resource `name`: `cloudscheduler.jobs.get`. #### Query Parameters None ### Request Example ``` GET /jobs/projects/PROJECT_ID/locations/LOCATION_ID/jobs/JOB_ID ``` ### Response #### Success Response (200) - **name** (string) - The name of the job. - **schedule** (string) - The schedule string for the job. - **appEngineHttpTarget** (object) - Details about the App Engine HTTP target. #### Response Example ```json { "name": "projects/PROJECT_ID/locations/LOCATION_ID/jobs/JOB_ID", "schedule": "* * * * *", "appEngineHttpTarget": { "httpMethod": "POST", "relativeUri": "/my-app-endpoint" } } ``` ``` -------------------------------- ### Create a Service Account Source: https://docs.cloud.google.com/scheduler/docs/authentication Create a new service account with a specified name. Ensure you have the necessary IAM permissions to perform this action. ```bash gcloud iam service-accounts create SERVICE_ACCOUNT_NAME ``` -------------------------------- ### GET /operations Source: https://docs.cloud.google.com/scheduler/docs/reference/rpc/google.longrunning Lists operations that match the specified filter. ```APIDOC ## GET /operations ### Description Lists operations that match the specified filter in the request. ### Method GET ### Endpoint /operations ### Parameters #### Query Parameters - **name** (string) - Required - The name of the operation's parent resource. - **filter** (string) - Optional - The standard list filter. - **page_size** (int32) - Optional - The standard list page size. - **page_token** (string) - Optional - The standard list page token. ``` -------------------------------- ### Example policy output Source: https://docs.cloud.google.com/scheduler/docs/limiting This represents the expected output format when describing an existing organization policy. ```yaml etag: CJTvgc0GENDs+50B- name: projects/PROJECT_NUMBER/policies/cloudscheduler.allowedTargetTypes spec: etag: CJTvgc0GENDs+50B inheritFromParent: true rules: - values: allowedValues: - PUBSUB updateTime: '2026-02-26T16:40:52.331282Z' ``` -------------------------------- ### GET /locations/{name} Source: https://docs.cloud.google.com/scheduler/docs/reference/rpc/google.cloud.location?hl=es-419 Retrieves information about a specific location. ```APIDOC ## GET /locations/{name} ### Description Gets information about a specific location. ### Method GET ### Endpoint /locations/{name} ### Parameters #### Path Parameters - **name** (string) - Required - Resource name for the location. ### Response #### Success Response (200) - **name** (string) - Resource name for the location. - **location_id** (string) - The canonical id for this location. - **display_name** (string) - The friendly name for this location. - **labels** (map) - Cross-service attributes for the location. - **metadata** (Any) - Service-specific metadata. ``` -------------------------------- ### POST /v1/{name}:run Source: https://docs.cloud.google.com/scheduler/docs/reference/rpc/google.cloud.scheduler.v1beta1?hl=fr Forces a job to run immediately. ```APIDOC ## POST /v1/{name}:run ### Description Forces a job to run now. ### Method POST ### Endpoint /v1/{name}:run ### Parameters #### Path Parameters - **name** (string) - Required - The job name. #### Request Body - **legacy_app_engine_cron** (bool) - Optional - If true, manages legacy App Engine Cron jobs. ``` -------------------------------- ### GET projects.locations.jobs.get Source: https://docs.cloud.google.com/scheduler/docs/reference/rest/v1/projects.locations.jobs/get?hl=pt-br Retrieves a specific job by its resource name. ```APIDOC ## GET https://cloudscheduler.googleapis.com/v1/{name=projects/*/locations/*/jobs/*} ### Description Gets a job from the Cloud Scheduler service. ### Method GET ### Endpoint https://cloudscheduler.googleapis.com/v1/{name} ### Parameters #### Path Parameters - **name** (string) - Required - The job name. For example: projects/PROJECT_ID/locations/LOCATION_ID/jobs/JOB_ID. ### Response #### Success Response (200) - **Job** (object) - An instance of the Job resource. ### Authorization Scopes - https://www.googleapis.com/auth/cloud-platform - https://www.googleapis.com/auth/cloud-scheduler ``` -------------------------------- ### POST /v1/{name}:run Source: https://docs.cloud.google.com/scheduler/docs/reference/rpc/google.cloud.scheduler.v1beta1?hl=es-419 Forces a job to run immediately. ```APIDOC ## POST /v1/{name}:run ### Description Forces a job to run now. ### Method POST ### Endpoint /v1/{name}:run ### Parameters #### Path Parameters - **name** (string) - Required - The job name. #### Request Body - **legacy_app_engine_cron** (bool) - Optional - If set to true, the job in the __cron queue with the corresponding name will be forced to run instead. ``` -------------------------------- ### POST /projects/{project_id}/locations/{location_id}/jobs/{job_id}:run Source: https://docs.cloud.google.com/scheduler/docs/reference/rpc/google.cloud.scheduler.v1?hl=es Forces a job to run immediately. ```APIDOC ## POST /projects/{project_id}/locations/{location_id}/jobs/{job_id}:run ### Description Request message for forcing a job to run now using RunJob. ### Method POST ### Endpoint projects/{PROJECT_ID}/locations/{LOCATION_ID}/jobs/{JOB_ID}:run ### Parameters #### Path Parameters - **name** (string) - Required - The job name (e.g., projects/PROJECT_ID/locations/LOCATION_ID/jobs/JOB_ID). ``` -------------------------------- ### GET projects.locations.jobs.get Source: https://docs.cloud.google.com/scheduler/docs/reference/rest/v1/projects.locations.jobs/get?hl=fr Retrieves a specific job by its resource name. ```APIDOC ## GET https://cloudscheduler.googleapis.com/v1/{name} ### Description Gets a job from the Cloud Scheduler service. ### Method GET ### Endpoint https://cloudscheduler.googleapis.com/v1/{name=projects/*/locations/*/jobs/*} ### Parameters #### Path Parameters - **name** (string) - Required - The job name. For example: projects/PROJECT_ID/locations/LOCATION_ID/jobs/JOB_ID. ### Response #### Success Response (200) - **Job** (object) - An instance of the Job resource. ### Authorization Scopes - https://www.googleapis.com/auth/cloud-platform - https://www.googleapis.com/auth/cloud-scheduler ```