Class CloudSchedulerClient (2.23.0)

publicclass CloudSchedulerClientimplementsBackgroundResource

Service Description: The Cloud Scheduler API allows external entities to reliably schedule asynchronous jobs.

This class provides the ability to make remote calls to the backing service through method calls that map to API methods. Sample code to get started:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try(CloudSchedulerClientcloudSchedulerClient=CloudSchedulerClient.create()){
JobNamename=JobName.of("[PROJECT]","[LOCATION]","[JOB]");
Jobresponse=cloudSchedulerClient.getJob(name);
}

Note: close() needs to be called on the CloudSchedulerClient object to clean up resources such as threads. In the example above, try-with-resources is used, which automatically calls close().

The surface of this class includes several types of Java methods for each of the API's methods:

  1. A "flattened" method. With this type of method, the fields of the request type have been converted into function parameters. It may be the case that not all fields are available as parameters, and not every API method will have a flattened method entry point.
  2. A "request object" method. This type of method only takes one parameter, a request object, which must be constructed before the call. Not every API method will have a request object method.
  3. A "callable" method. This type of method takes no parameters and returns an immutable API callable object, which can be used to initiate calls to the service.

See the individual methods for example code.

Many parameters require resource names to be formatted in a particular way. To assist with these names, this class includes a format method for each type of name, and additionally a parse method to extract the individual identifiers contained within names that are returned.

This class can be customized by passing in a custom instance of CloudSchedulerSettings to create(). For example:

To customize credentials:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
CloudSchedulerSettingscloudSchedulerSettings=
CloudSchedulerSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
.build();
CloudSchedulerClientcloudSchedulerClient=CloudSchedulerClient.create(cloudSchedulerSettings);

To customize the endpoint:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
CloudSchedulerSettingscloudSchedulerSettings=
CloudSchedulerSettings.newBuilder().setEndpoint(myEndpoint).build();
CloudSchedulerClientcloudSchedulerClient=CloudSchedulerClient.create(cloudSchedulerSettings);

To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over the wire:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
CloudSchedulerSettingscloudSchedulerSettings=
CloudSchedulerSettings.newHttpJsonBuilder().build();
CloudSchedulerClientcloudSchedulerClient=CloudSchedulerClient.create(cloudSchedulerSettings);

Please refer to the GitHub repository's samples for more quickstart code snippets.

Inheritance

java.lang.Object > CloudSchedulerClient

Implements

BackgroundResource

Static Methods

create()

publicstaticfinalCloudSchedulerClientcreate()

Constructs an instance of CloudSchedulerClient with default settings.

Returns
Type Description
CloudSchedulerClient
Exceptions
Type Description
IOException

create(CloudSchedulerSettings settings)

publicstaticfinalCloudSchedulerClientcreate(CloudSchedulerSettingssettings)

Constructs an instance of CloudSchedulerClient, using the given settings. The channels are created based on the settings passed in, or defaults for any settings that are not set.

Parameter
Name Description
settings CloudSchedulerSettings
Returns
Type Description
CloudSchedulerClient
Exceptions
Type Description
IOException

create(CloudSchedulerStub stub)

publicstaticfinalCloudSchedulerClientcreate(CloudSchedulerStubstub)

Constructs an instance of CloudSchedulerClient, using the given stub for making calls. This is for advanced usage - prefer using create(CloudSchedulerSettings).

Parameter
Name Description
stub CloudSchedulerStub
Returns
Type Description
CloudSchedulerClient

Constructors

CloudSchedulerClient(CloudSchedulerSettings settings)

protectedCloudSchedulerClient(CloudSchedulerSettingssettings)

Constructs an instance of CloudSchedulerClient, using the given settings. This is protected so that it is easy to make a subclass, but otherwise, the static factory methods should be preferred.

Parameter
Name Description
settings CloudSchedulerSettings

CloudSchedulerClient(CloudSchedulerStub stub)

protectedCloudSchedulerClient(CloudSchedulerStubstub)
Parameter
Name Description
stub CloudSchedulerStub

Methods

awaitTermination(long duration, TimeUnit unit)

publicbooleanawaitTermination(longduration,TimeUnitunit)
Parameters
Name Description
duration long
unit TimeUnit
Returns
Type Description
boolean
Exceptions
Type Description
InterruptedException

close()

publicfinalvoidclose()

createJob(CreateJobRequest request)

publicfinalJobcreateJob(CreateJobRequestrequest)

Creates a job.

Sample code:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try(CloudSchedulerClientcloudSchedulerClient=CloudSchedulerClient.create()){
CreateJobRequestrequest=
CreateJobRequest.newBuilder()
.setParent(LocationName.of("[PROJECT]","[LOCATION]").toString())
.setJob(Job.newBuilder().build())
.build();
Jobresponse=cloudSchedulerClient.createJob(request);
}
Parameter
Name Description
request CreateJobRequest

The request object containing all of the parameters for the API call.

Returns
Type Description
Job

createJob(LocationName parent, Job job)

publicfinalJobcreateJob(LocationNameparent,Jobjob)

Creates a job.

Sample code:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try(CloudSchedulerClientcloudSchedulerClient=CloudSchedulerClient.create()){
LocationNameparent=LocationName.of("[PROJECT]","[LOCATION]");
Jobjob=Job.newBuilder().build();
Jobresponse=cloudSchedulerClient.createJob(parent,job);
}
Parameters
Name Description
parent LocationName

Required. The location name. For example: projects/PROJECT_ID/locations/LOCATION_ID.

job Job

Required. The job to add. The user can optionally specify a name for the job in name. name cannot be the same as an existing job. If a name is not specified then the system will generate a random unique name that will be returned (name) in the response.

Returns
Type Description
Job

createJob(String parent, Job job)

publicfinalJobcreateJob(Stringparent,Jobjob)

Creates a job.

Sample code:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try(CloudSchedulerClientcloudSchedulerClient=CloudSchedulerClient.create()){
Stringparent=LocationName.of("[PROJECT]","[LOCATION]").toString();
Jobjob=Job.newBuilder().build();
Jobresponse=cloudSchedulerClient.createJob(parent,job);
}
Parameters
Name Description
parent String

Required. The location name. For example: projects/PROJECT_ID/locations/LOCATION_ID.

job Job

Required. The job to add. The user can optionally specify a name for the job in name. name cannot be the same as an existing job. If a name is not specified then the system will generate a random unique name that will be returned (name) in the response.

Returns
Type Description
Job

createJobCallable()

publicfinalUnaryCallable<CreateJobRequest,Job>createJobCallable()

Creates a job.

Sample code:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try(CloudSchedulerClientcloudSchedulerClient=CloudSchedulerClient.create()){
CreateJobRequestrequest=
CreateJobRequest.newBuilder()
.setParent(LocationName.of("[PROJECT]","[LOCATION]").toString())
.setJob(Job.newBuilder().build())
.build();
ApiFuture<Job>future=cloudSchedulerClient.createJobCallable().futureCall(request);
// Do something.
Jobresponse=future.get();
}
Returns
Type Description
UnaryCallable<CreateJobRequest,Job>

deleteJob(DeleteJobRequest request)

publicfinalvoiddeleteJob(DeleteJobRequestrequest)

Deletes a job.

Sample code:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try(CloudSchedulerClientcloudSchedulerClient=CloudSchedulerClient.create()){
DeleteJobRequestrequest=
DeleteJobRequest.newBuilder()
.setName(JobName.of("[PROJECT]","[LOCATION]","[JOB]").toString())
.setLegacyAppEngineCron(true)
.build();
cloudSchedulerClient.deleteJob(request);
}
Parameter
Name Description
request DeleteJobRequest

The request object containing all of the parameters for the API call.

deleteJob(JobName name)

publicfinalvoiddeleteJob(JobNamename)

Deletes a job.

Sample code:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try(CloudSchedulerClientcloudSchedulerClient=CloudSchedulerClient.create()){
JobNamename=JobName.of("[PROJECT]","[LOCATION]","[JOB]");
cloudSchedulerClient.deleteJob(name);
}
Parameter
Name Description
name JobName

Required. The job name. For example: projects/PROJECT_ID/locations/LOCATION_ID/jobs/JOB_ID.

deleteJob(String name)

publicfinalvoiddeleteJob(Stringname)

Deletes a job.

Sample code:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try(CloudSchedulerClientcloudSchedulerClient=CloudSchedulerClient.create()){
Stringname=JobName.of("[PROJECT]","[LOCATION]","[JOB]").toString();
cloudSchedulerClient.deleteJob(name);
}
Parameter
Name Description
name String

Required. The job name. For example: projects/PROJECT_ID/locations/LOCATION_ID/jobs/JOB_ID.

deleteJobCallable()

publicfinalUnaryCallable<DeleteJobRequest,Empty>deleteJobCallable()

Deletes a job.

Sample code:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try(CloudSchedulerClientcloudSchedulerClient=CloudSchedulerClient.create()){
DeleteJobRequestrequest=
DeleteJobRequest.newBuilder()
.setName(JobName.of("[PROJECT]","[LOCATION]","[JOB]").toString())
.setLegacyAppEngineCron(true)
.build();
ApiFuture<Empty>future=cloudSchedulerClient.deleteJobCallable().futureCall(request);
// Do something.
future.get();
}
Returns
Type Description
UnaryCallable<DeleteJobRequest,Empty>

getJob(GetJobRequest request)

publicfinalJobgetJob(GetJobRequestrequest)

Gets a job.

Sample code:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try(CloudSchedulerClientcloudSchedulerClient=CloudSchedulerClient.create()){
GetJobRequestrequest=
GetJobRequest.newBuilder()
.setName(JobName.of("[PROJECT]","[LOCATION]","[JOB]").toString())
.build();
Jobresponse=cloudSchedulerClient.getJob(request);
}
Parameter
Name Description
request GetJobRequest

The request object containing all of the parameters for the API call.

Returns
Type Description
Job

getJob(JobName name)

publicfinalJobgetJob(JobNamename)

Gets a job.

Sample code:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try(CloudSchedulerClientcloudSchedulerClient=CloudSchedulerClient.create()){
JobNamename=JobName.of("[PROJECT]","[LOCATION]","[JOB]");
Jobresponse=cloudSchedulerClient.getJob(name);
}
Parameter
Name Description
name JobName

Required. The job name. For example: projects/PROJECT_ID/locations/LOCATION_ID/jobs/JOB_ID.

Returns
Type Description
Job

getJob(String name)

publicfinalJobgetJob(Stringname)

Gets a job.

Sample code:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try(CloudSchedulerClientcloudSchedulerClient=CloudSchedulerClient.create()){
Stringname=JobName.of("[PROJECT]","[LOCATION]","[JOB]").toString();
Jobresponse=cloudSchedulerClient.getJob(name);
}
Parameter
Name Description
name String

Required. The job name. For example: projects/PROJECT_ID/locations/LOCATION_ID/jobs/JOB_ID.

Returns
Type Description
Job

getJobCallable()

publicfinalUnaryCallable<GetJobRequest,Job>getJobCallable()

Gets a job.

Sample code:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try(CloudSchedulerClientcloudSchedulerClient=CloudSchedulerClient.create()){
GetJobRequestrequest=
GetJobRequest.newBuilder()
.setName(JobName.of("[PROJECT]","[LOCATION]","[JOB]").toString())
.build();
ApiFuture<Job>future=cloudSchedulerClient.getJobCallable().futureCall(request);
// Do something.
Jobresponse=future.get();
}
Returns
Type Description
UnaryCallable<GetJobRequest,Job>

getLocation(GetLocationRequest request)

publicfinalLocationgetLocation(GetLocationRequestrequest)

Gets information about a location.

Sample code:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try(CloudSchedulerClientcloudSchedulerClient=CloudSchedulerClient.create()){
GetLocationRequestrequest=GetLocationRequest.newBuilder().setName("name3373707").build();
Locationresponse=cloudSchedulerClient.getLocation(request);
}
Parameter
Name Description
request com.google.cloud.location.GetLocationRequest

The request object containing all of the parameters for the API call.

Returns
Type Description
com.google.cloud.location.Location

getLocationCallable()

publicfinalUnaryCallable<GetLocationRequest,Location>getLocationCallable()

Gets information about a location.

Sample code:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try(CloudSchedulerClientcloudSchedulerClient=CloudSchedulerClient.create()){
GetLocationRequestrequest=GetLocationRequest.newBuilder().setName("name3373707").build();
ApiFuture<Location>future=cloudSchedulerClient.getLocationCallable().futureCall(request);
// Do something.
Locationresponse=future.get();
}
Returns
Type Description
UnaryCallable<com.google.cloud.location.GetLocationRequest,com.google.cloud.location.Location>

getSettings()

publicfinalCloudSchedulerSettingsgetSettings()
Returns
Type Description
CloudSchedulerSettings

getStub()

publicCloudSchedulerStubgetStub()
Returns
Type Description
CloudSchedulerStub

isShutdown()

publicbooleanisShutdown()
Returns
Type Description
boolean

isTerminated()

publicbooleanisTerminated()
Returns
Type Description
boolean

listJobs(ListJobsRequest request)

publicfinalCloudSchedulerClient.ListJobsPagedResponselistJobs(ListJobsRequestrequest)

Lists jobs.

Sample code:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try(CloudSchedulerClientcloudSchedulerClient=CloudSchedulerClient.create()){
ListJobsRequestrequest=
ListJobsRequest.newBuilder()
.setParent(LocationName.of("[PROJECT]","[LOCATION]").toString())
.setFilter("filter-1274492040")
.setPageSize(883849137)
.setPageToken("pageToken873572522")
.setLegacyAppEngineCron(true)
.build();
for(Jobelement:cloudSchedulerClient.listJobs(request).iterateAll()){
// doThingsWith(element);
}
}
Parameter
Name Description
request ListJobsRequest

The request object containing all of the parameters for the API call.

Returns
Type Description
CloudSchedulerClient.ListJobsPagedResponse

listJobs(LocationName parent)

publicfinalCloudSchedulerClient.ListJobsPagedResponselistJobs(LocationNameparent)

Lists jobs.

Sample code:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try(CloudSchedulerClientcloudSchedulerClient=CloudSchedulerClient.create()){
LocationNameparent=LocationName.of("[PROJECT]","[LOCATION]");
for(Jobelement:cloudSchedulerClient.listJobs(parent).iterateAll()){
// doThingsWith(element);
}
}
Parameter
Name Description
parent LocationName

Required. The location name. For example: projects/PROJECT_ID/locations/LOCATION_ID.

Returns
Type Description
CloudSchedulerClient.ListJobsPagedResponse

listJobs(String parent)

publicfinalCloudSchedulerClient.ListJobsPagedResponselistJobs(Stringparent)

Lists jobs.

Sample code:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try(CloudSchedulerClientcloudSchedulerClient=CloudSchedulerClient.create()){
Stringparent=LocationName.of("[PROJECT]","[LOCATION]").toString();
for(Jobelement:cloudSchedulerClient.listJobs(parent).iterateAll()){
// doThingsWith(element);
}
}
Parameter
Name Description
parent String

Required. The location name. For example: projects/PROJECT_ID/locations/LOCATION_ID.

Returns
Type Description
CloudSchedulerClient.ListJobsPagedResponse

listJobsCallable()

publicfinalUnaryCallable<ListJobsRequest,ListJobsResponse>listJobsCallable()

Lists jobs.

Sample code:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try(CloudSchedulerClientcloudSchedulerClient=CloudSchedulerClient.create()){
ListJobsRequestrequest=
ListJobsRequest.newBuilder()
.setParent(LocationName.of("[PROJECT]","[LOCATION]").toString())
.setFilter("filter-1274492040")
.setPageSize(883849137)
.setPageToken("pageToken873572522")
.setLegacyAppEngineCron(true)
.build();
while(true){
ListJobsResponseresponse=cloudSchedulerClient.listJobsCallable().call(request);
for(Jobelement:response.getJobsList()){
// doThingsWith(element);
}
StringnextPageToken=response.getNextPageToken();
if(!Strings.isNullOrEmpty(nextPageToken)){
request=request.toBuilder().setPageToken(nextPageToken).build();
}else{
break;
}
}
}
Returns
Type Description
UnaryCallable<ListJobsRequest,ListJobsResponse>

listJobsPagedCallable()

publicfinalUnaryCallable<ListJobsRequest,CloudSchedulerClient.ListJobsPagedResponse>listJobsPagedCallable()

Lists jobs.

Sample code:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try(CloudSchedulerClientcloudSchedulerClient=CloudSchedulerClient.create()){
ListJobsRequestrequest=
ListJobsRequest.newBuilder()
.setParent(LocationName.of("[PROJECT]","[LOCATION]").toString())
.setFilter("filter-1274492040")
.setPageSize(883849137)
.setPageToken("pageToken873572522")
.setLegacyAppEngineCron(true)
.build();
ApiFuture<Job>future=cloudSchedulerClient.listJobsPagedCallable().futureCall(request);
// Do something.
for(Jobelement:future.get().iterateAll()){
// doThingsWith(element);
}
}
Returns
Type Description
UnaryCallable<ListJobsRequest,ListJobsPagedResponse>

listLocations(ListLocationsRequest request)

publicfinalCloudSchedulerClient.ListLocationsPagedResponselistLocations(ListLocationsRequestrequest)

Lists information about the supported locations for this service.

Sample code:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try(CloudSchedulerClientcloudSchedulerClient=CloudSchedulerClient.create()){
ListLocationsRequestrequest=
ListLocationsRequest.newBuilder()
.setName("name3373707")
.setFilter("filter-1274492040")
.setPageSize(883849137)
.setPageToken("pageToken873572522")
.build();
for(Locationelement:cloudSchedulerClient.listLocations(request).iterateAll()){
// doThingsWith(element);
}
}
Parameter
Name Description
request com.google.cloud.location.ListLocationsRequest

The request object containing all of the parameters for the API call.

Returns
Type Description
CloudSchedulerClient.ListLocationsPagedResponse

listLocationsCallable()

publicfinalUnaryCallable<ListLocationsRequest,ListLocationsResponse>listLocationsCallable()

Lists information about the supported locations for this service.

Sample code:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try(CloudSchedulerClientcloudSchedulerClient=CloudSchedulerClient.create()){
ListLocationsRequestrequest=
ListLocationsRequest.newBuilder()
.setName("name3373707")
.setFilter("filter-1274492040")
.setPageSize(883849137)
.setPageToken("pageToken873572522")
.build();
while(true){
ListLocationsResponseresponse=cloudSchedulerClient.listLocationsCallable().call(request);
for(Locationelement:response.getLocationsList()){
// doThingsWith(element);
}
StringnextPageToken=response.getNextPageToken();
if(!Strings.isNullOrEmpty(nextPageToken)){
request=request.toBuilder().setPageToken(nextPageToken).build();
}else{
break;
}
}
}
Returns
Type Description
UnaryCallable<com.google.cloud.location.ListLocationsRequest,com.google.cloud.location.ListLocationsResponse>

listLocationsPagedCallable()

publicfinalUnaryCallable<ListLocationsRequest,CloudSchedulerClient.ListLocationsPagedResponse>listLocationsPagedCallable()

Lists information about the supported locations for this service.

Sample code:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try(CloudSchedulerClientcloudSchedulerClient=CloudSchedulerClient.create()){
ListLocationsRequestrequest=
ListLocationsRequest.newBuilder()
.setName("name3373707")
.setFilter("filter-1274492040")
.setPageSize(883849137)
.setPageToken("pageToken873572522")
.build();
ApiFuture<Location>future=
cloudSchedulerClient.listLocationsPagedCallable().futureCall(request);
// Do something.
for(Locationelement:future.get().iterateAll()){
// doThingsWith(element);
}
}
Returns
Type Description
UnaryCallable<com.google.cloud.location.ListLocationsRequest,ListLocationsPagedResponse>

pauseJob(JobName name)

publicfinalJobpauseJob(JobNamename)

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.

Sample code:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try(CloudSchedulerClientcloudSchedulerClient=CloudSchedulerClient.create()){
JobNamename=JobName.of("[PROJECT]","[LOCATION]","[JOB]");
Jobresponse=cloudSchedulerClient.pauseJob(name);
}
Parameter
Name Description
name JobName

Required. The job name. For example: projects/PROJECT_ID/locations/LOCATION_ID/jobs/JOB_ID.

Returns
Type Description
Job

pauseJob(PauseJobRequest request)

publicfinalJobpauseJob(PauseJobRequestrequest)

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.

Sample code:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try(CloudSchedulerClientcloudSchedulerClient=CloudSchedulerClient.create()){
PauseJobRequestrequest=
PauseJobRequest.newBuilder()
.setName(JobName.of("[PROJECT]","[LOCATION]","[JOB]").toString())
.build();
Jobresponse=cloudSchedulerClient.pauseJob(request);
}
Parameter
Name Description
request PauseJobRequest

The request object containing all of the parameters for the API call.

Returns
Type Description
Job

pauseJob(String name)

publicfinalJobpauseJob(Stringname)

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.

Sample code:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try(CloudSchedulerClientcloudSchedulerClient=CloudSchedulerClient.create()){
Stringname=JobName.of("[PROJECT]","[LOCATION]","[JOB]").toString();
Jobresponse=cloudSchedulerClient.pauseJob(name);
}
Parameter
Name Description
name String

Required. The job name. For example: projects/PROJECT_ID/locations/LOCATION_ID/jobs/JOB_ID.

Returns
Type Description
Job

pauseJobCallable()

publicfinalUnaryCallable<PauseJobRequest,Job>pauseJobCallable()

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.

Sample code:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try(CloudSchedulerClientcloudSchedulerClient=CloudSchedulerClient.create()){
PauseJobRequestrequest=
PauseJobRequest.newBuilder()
.setName(JobName.of("[PROJECT]","[LOCATION]","[JOB]").toString())
.build();
ApiFuture<Job>future=cloudSchedulerClient.pauseJobCallable().futureCall(request);
// Do something.
Jobresponse=future.get();
}
Returns
Type Description
UnaryCallable<PauseJobRequest,Job>

resumeJob(JobName name)

publicfinalJobresumeJob(JobNamename)

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.

Sample code:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try(CloudSchedulerClientcloudSchedulerClient=CloudSchedulerClient.create()){
JobNamename=JobName.of("[PROJECT]","[LOCATION]","[JOB]");
Jobresponse=cloudSchedulerClient.resumeJob(name);
}
Parameter
Name Description
name JobName

Required. The job name. For example: projects/PROJECT_ID/locations/LOCATION_ID/jobs/JOB_ID.

Returns
Type Description
Job

resumeJob(ResumeJobRequest request)

publicfinalJobresumeJob(ResumeJobRequestrequest)

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.

Sample code:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try(CloudSchedulerClientcloudSchedulerClient=CloudSchedulerClient.create()){
ResumeJobRequestrequest=
ResumeJobRequest.newBuilder()
.setName(JobName.of("[PROJECT]","[LOCATION]","[JOB]").toString())
.build();
Jobresponse=cloudSchedulerClient.resumeJob(request);
}
Parameter
Name Description
request ResumeJobRequest

The request object containing all of the parameters for the API call.

Returns
Type Description
Job

resumeJob(String name)

publicfinalJobresumeJob(Stringname)

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.

Sample code:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try(CloudSchedulerClientcloudSchedulerClient=CloudSchedulerClient.create()){
Stringname=JobName.of("[PROJECT]","[LOCATION]","[JOB]").toString();
Jobresponse=cloudSchedulerClient.resumeJob(name);
}
Parameter
Name Description
name String

Required. The job name. For example: projects/PROJECT_ID/locations/LOCATION_ID/jobs/JOB_ID.

Returns
Type Description
Job

resumeJobCallable()

publicfinalUnaryCallable<ResumeJobRequest,Job>resumeJobCallable()

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.

Sample code:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try(CloudSchedulerClientcloudSchedulerClient=CloudSchedulerClient.create()){
ResumeJobRequestrequest=
ResumeJobRequest.newBuilder()
.setName(JobName.of("[PROJECT]","[LOCATION]","[JOB]").toString())
.build();
ApiFuture<Job>future=cloudSchedulerClient.resumeJobCallable().futureCall(request);
// Do something.
Jobresponse=future.get();
}
Returns
Type Description
UnaryCallable<ResumeJobRequest,Job>

runJob(JobName name)

publicfinalJobrunJob(JobNamename)

Forces a job to run now.

When this method is called, Cloud Scheduler will dispatch the job, even if the job is already running.

Sample code:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try(CloudSchedulerClientcloudSchedulerClient=CloudSchedulerClient.create()){
JobNamename=JobName.of("[PROJECT]","[LOCATION]","[JOB]");
Jobresponse=cloudSchedulerClient.runJob(name);
}
Parameter
Name Description
name JobName

Required. The job name. For example: projects/PROJECT_ID/locations/LOCATION_ID/jobs/JOB_ID.

Returns
Type Description
Job

runJob(RunJobRequest request)

publicfinalJobrunJob(RunJobRequestrequest)

Forces a job to run now.

When this method is called, Cloud Scheduler will dispatch the job, even if the job is already running.

Sample code:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try(CloudSchedulerClientcloudSchedulerClient=CloudSchedulerClient.create()){
RunJobRequestrequest=
RunJobRequest.newBuilder()
.setName(JobName.of("[PROJECT]","[LOCATION]","[JOB]").toString())
.setLegacyAppEngineCron(true)
.build();
Jobresponse=cloudSchedulerClient.runJob(request);
}
Parameter
Name Description
request RunJobRequest

The request object containing all of the parameters for the API call.

Returns
Type Description
Job

runJob(String name)

publicfinalJobrunJob(Stringname)

Forces a job to run now.

When this method is called, Cloud Scheduler will dispatch the job, even if the job is already running.

Sample code:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try(CloudSchedulerClientcloudSchedulerClient=CloudSchedulerClient.create()){
Stringname=JobName.of("[PROJECT]","[LOCATION]","[JOB]").toString();
Jobresponse=cloudSchedulerClient.runJob(name);
}
Parameter
Name Description
name String

Required. The job name. For example: projects/PROJECT_ID/locations/LOCATION_ID/jobs/JOB_ID.

Returns
Type Description
Job

runJobCallable()

publicfinalUnaryCallable<RunJobRequest,Job>runJobCallable()

Forces a job to run now.

When this method is called, Cloud Scheduler will dispatch the job, even if the job is already running.

Sample code:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try(CloudSchedulerClientcloudSchedulerClient=CloudSchedulerClient.create()){
RunJobRequestrequest=
RunJobRequest.newBuilder()
.setName(JobName.of("[PROJECT]","[LOCATION]","[JOB]").toString())
.setLegacyAppEngineCron(true)
.build();
ApiFuture<Job>future=cloudSchedulerClient.runJobCallable().futureCall(request);
// Do something.
Jobresponse=future.get();
}
Returns
Type Description
UnaryCallable<RunJobRequest,Job>

shutdown()

publicvoidshutdown()

shutdownNow()

publicvoidshutdownNow()

updateJob(Job job, FieldMask updateMask)

publicfinalJobupdateJob(Jobjob,FieldMaskupdateMask)

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.

Sample code:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try(CloudSchedulerClientcloudSchedulerClient=CloudSchedulerClient.create()){
Jobjob=Job.newBuilder().build();
FieldMaskupdateMask=FieldMask.newBuilder().build();
Jobresponse=cloudSchedulerClient.updateJob(job,updateMask);
}
Parameters
Name Description
job Job

Required. The new job properties. name must be specified.

Output only fields cannot be modified using UpdateJob. Any value specified for an output only field will be ignored.

updateMask FieldMask

A mask used to specify which fields of the job are being updated.

Returns
Type Description
Job

updateJob(UpdateJobRequest request)

publicfinalJobupdateJob(UpdateJobRequestrequest)

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.

Sample code:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try(CloudSchedulerClientcloudSchedulerClient=CloudSchedulerClient.create()){
UpdateJobRequestrequest=
UpdateJobRequest.newBuilder()
.setJob(Job.newBuilder().build())
.setUpdateMask(FieldMask.newBuilder().build())
.build();
Jobresponse=cloudSchedulerClient.updateJob(request);
}
Parameter
Name Description
request UpdateJobRequest

The request object containing all of the parameters for the API call.

Returns
Type Description
Job

updateJobCallable()

publicfinalUnaryCallable<UpdateJobRequest,Job>updateJobCallable()

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.

Sample code:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try(CloudSchedulerClientcloudSchedulerClient=CloudSchedulerClient.create()){
UpdateJobRequestrequest=
UpdateJobRequest.newBuilder()
.setJob(Job.newBuilder().build())
.setUpdateMask(FieldMask.newBuilder().build())
.build();
ApiFuture<Job>future=cloudSchedulerClient.updateJobCallable().futureCall(request);
// Do something.
Jobresponse=future.get();
}
Returns
Type Description
UnaryCallable<UpdateJobRequest,Job>

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 the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025年10月30日 UTC.