Package scheduler is an auto-generated package for the Cloud Scheduler API.
Creates and manages jobs run on a regular recurring schedule.
General documentation
For information that is relevant for all client libraries please reference https://pkg.go.dev/cloud.google.com/go#pkg-overview. Some information on this page includes:
- Authentication and Authorization
- Timeouts and Cancellation
- Testing against Client Libraries
- Debugging Client Libraries
- Inspecting errors
Example usage
To get started with this package, create a client.
ctx := context.Background() // 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://pkg.go.dev/cloud.google.com/go#hdr-Client_Options c, err := scheduler.NewCloudSchedulerClient(ctx) if err != nil { // TODO: Handle error. } defer c.Close()
The client will use your default application credentials. Clients should be reused instead of created as needed. The methods of Client are safe for concurrent use by multiple goroutines. The returned client must be Closed when it is done being used.
Using the Client
The following is an example of making an API call with the newly created client.
ctx := context.Background() // 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://pkg.go.dev/cloud.google.com/go#hdr-Client_Options c, err := scheduler.NewCloudSchedulerClient(ctx) if err != nil { // TODO: Handle error. } defer c.Close() req := &schedulerpb.CreateJobRequest{ // TODO: Fill request struct fields. // See https://pkg.go.dev/cloud.google.com/go/scheduler/apiv1/schedulerpb#CreateJobRequest. } resp, err := c.CreateJob(ctx, req) if err != nil { // TODO: Handle error. } // TODO: Use resp. _ = resp
Use of Context
The ctx passed to NewCloudSchedulerClient is used for authentication requests and for creating the underlying connection, but is not used for subsequent calls. Individual methods on the client use the ctx given to them.
To close the open connection, use the Close() method.
Functions
func DefaultAuthScopes
func DefaultAuthScopes() []string
DefaultAuthScopes reports the default set of authentication scopes to use with this package.
CloudSchedulerCallOptions
type CloudSchedulerCallOptions struct {
ListJobs []gax.CallOption
GetJob []gax.CallOption
CreateJob []gax.CallOption
UpdateJob []gax.CallOption
DeleteJob []gax.CallOption
PauseJob []gax.CallOption
ResumeJob []gax.CallOption
RunJob []gax.CallOption
GetLocation []gax.CallOption
ListLocations []gax.CallOption
}
CloudSchedulerCallOptions contains the retry settings for each method of CloudSchedulerClient.
CloudSchedulerClient
type CloudSchedulerClient struct {
// The call options for this service.
CallOptions *CloudSchedulerCallOptions
// contains filtered or unexported fields
}
CloudSchedulerClient is a client for interacting with Cloud Scheduler API. Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
The Cloud Scheduler API allows external entities to reliably schedule asynchronous jobs.
func NewCloudSchedulerClient
func NewCloudSchedulerClient(ctx context.Context, opts ...option.ClientOption) (*CloudSchedulerClient, error)
NewCloudSchedulerClient creates a new cloud scheduler client based on gRPC. The returned client must be Closed when it is done being used to clean up its underlying connections.
The Cloud Scheduler API allows external entities to reliably schedule asynchronous jobs.
Example
package main
import (
"context"
scheduler "cloud.google.com/go/scheduler/apiv1"
)
func main() {
ctx := context.Background()
// 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://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := scheduler.NewCloudSchedulerClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
// TODO: Use client.
_ = c
}
func NewCloudSchedulerRESTClient
func NewCloudSchedulerRESTClient(ctx context.Context, opts ...option.ClientOption) (*CloudSchedulerClient, error)
NewCloudSchedulerRESTClient creates a new cloud scheduler rest client.
The Cloud Scheduler API allows external entities to reliably schedule asynchronous jobs.
Example
package main
import (
"context"
scheduler "cloud.google.com/go/scheduler/apiv1"
)
func main() {
ctx := context.Background()
// 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://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := scheduler.NewCloudSchedulerRESTClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
// TODO: Use client.
_ = c
}
func (*CloudSchedulerClient) Close
func (c *CloudSchedulerClient) Close() error
Close closes the connection to the API service. The user should invoke this when the client is no longer required.
func (*CloudSchedulerClient) Connection (deprecated)
func (c *CloudSchedulerClient) Connection() *grpc.ClientConn
Connection returns a connection to the API service.
Deprecated: Connections are now pooled so this method does not always return the same resource.
func (*CloudSchedulerClient) CreateJob
func (c *CloudSchedulerClient) CreateJob(ctx context.Context, req *schedulerpb.CreateJobRequest, opts ...gax.CallOption) (*schedulerpb.Job, error)
CreateJob creates a job.
Example
package main
import (
"context"
scheduler "cloud.google.com/go/scheduler/apiv1"
schedulerpb "cloud.google.com/go/scheduler/apiv1/schedulerpb"
)
func main() {
ctx := context.Background()
// 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://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := scheduler.NewCloudSchedulerClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &schedulerpb.CreateJobRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/scheduler/apiv1/schedulerpb#CreateJobRequest.
}
resp, err := c.CreateJob(ctx, req)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
func (*CloudSchedulerClient) DeleteJob
func (c *CloudSchedulerClient) DeleteJob(ctx context.Context, req *schedulerpb.DeleteJobRequest, opts ...gax.CallOption) error
DeleteJob deletes a job.
Example
package main
import (
"context"
scheduler "cloud.google.com/go/scheduler/apiv1"
schedulerpb "cloud.google.com/go/scheduler/apiv1/schedulerpb"
)
func main() {
ctx := context.Background()
// 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://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := scheduler.NewCloudSchedulerClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &schedulerpb.DeleteJobRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/scheduler/apiv1/schedulerpb#DeleteJobRequest.
}
err = c.DeleteJob(ctx, req)
if err != nil {
// TODO: Handle error.
}
}
func (*CloudSchedulerClient) GetJob
func (c *CloudSchedulerClient) GetJob(ctx context.Context, req *schedulerpb.GetJobRequest, opts ...gax.CallOption) (*schedulerpb.Job, error)
GetJob gets a job.
Example
package main
import (
"context"
scheduler "cloud.google.com/go/scheduler/apiv1"
schedulerpb "cloud.google.com/go/scheduler/apiv1/schedulerpb"
)
func main() {
ctx := context.Background()
// 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://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := scheduler.NewCloudSchedulerClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &schedulerpb.GetJobRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/scheduler/apiv1/schedulerpb#GetJobRequest.
}
resp, err := c.GetJob(ctx, req)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
func (*CloudSchedulerClient) GetLocation
func (c *CloudSchedulerClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error)
GetLocation gets information about a location.
Example
package main
import (
"context"
scheduler "cloud.google.com/go/scheduler/apiv1"
locationpb "google.golang.org/genproto/googleapis/cloud/location"
)
func main() {
ctx := context.Background()
// 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://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := scheduler.NewCloudSchedulerClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &locationpb.GetLocationRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/location#GetLocationRequest.
}
resp, err := c.GetLocation(ctx, req)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
func (*CloudSchedulerClient) ListJobs
func (c *CloudSchedulerClient) ListJobs(ctx context.Context, req *schedulerpb.ListJobsRequest, opts ...gax.CallOption) *JobIterator
ListJobs lists jobs.
Examples
package main
import (
"context"
scheduler "cloud.google.com/go/scheduler/apiv1"
schedulerpb "cloud.google.com/go/scheduler/apiv1/schedulerpb"
"google.golang.org/api/iterator"
)
func main() {
ctx := context.Background()
// 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://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := scheduler.NewCloudSchedulerClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &schedulerpb.ListJobsRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/scheduler/apiv1/schedulerpb#ListJobsRequest.
}
it := c.ListJobs(ctx, req)
for {
resp, err := it.Next()
if err == iterator.Done {
break
}
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
// If you need to access the underlying RPC response,
// you can do so by casting the `Response` as below.
// Otherwise, remove this line. Only populated after
// first call to Next(). Not safe for concurrent access.
_ = it.Response.(*schedulerpb.ListJobsResponse)
}
}
all
package main
import (
"context"
scheduler "cloud.google.com/go/scheduler/apiv1"
schedulerpb "cloud.google.com/go/scheduler/apiv1/schedulerpb"
)
func main() {
ctx := context.Background()
// 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://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := scheduler.NewCloudSchedulerClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &schedulerpb.ListJobsRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/scheduler/apiv1/schedulerpb#ListJobsRequest.
}
for resp, err := range c.ListJobs(ctx, req).All() {
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
}
func (*CloudSchedulerClient) ListLocations
func (c *CloudSchedulerClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator
ListLocations lists information about the supported locations for this service.
Examples
package main
import (
"context"
scheduler "cloud.google.com/go/scheduler/apiv1"
"google.golang.org/api/iterator"
locationpb "google.golang.org/genproto/googleapis/cloud/location"
)
func main() {
ctx := context.Background()
// 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://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := scheduler.NewCloudSchedulerClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &locationpb.ListLocationsRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/location#ListLocationsRequest.
}
it := c.ListLocations(ctx, req)
for {
resp, err := it.Next()
if err == iterator.Done {
break
}
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
// If you need to access the underlying RPC response,
// you can do so by casting the `Response` as below.
// Otherwise, remove this line. Only populated after
// first call to Next(). Not safe for concurrent access.
_ = it.Response.(*locationpb.ListLocationsResponse)
}
}
all
package main
import (
"context"
scheduler "cloud.google.com/go/scheduler/apiv1"
locationpb "google.golang.org/genproto/googleapis/cloud/location"
)
func main() {
ctx := context.Background()
// 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://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := scheduler.NewCloudSchedulerClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &locationpb.ListLocationsRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/location#ListLocationsRequest.
}
for resp, err := range c.ListLocations(ctx, req).All() {
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
}
func (*CloudSchedulerClient) PauseJob
func (c *CloudSchedulerClient) PauseJob(ctx context.Context, req *schedulerpb.PauseJobRequest, opts ...gax.CallOption) (*schedulerpb.Job, error)
PauseJob 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.
Example
package main
import (
"context"
scheduler "cloud.google.com/go/scheduler/apiv1"
schedulerpb "cloud.google.com/go/scheduler/apiv1/schedulerpb"
)
func main() {
ctx := context.Background()
// 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://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := scheduler.NewCloudSchedulerClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &schedulerpb.PauseJobRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/scheduler/apiv1/schedulerpb#PauseJobRequest.
}
resp, err := c.PauseJob(ctx, req)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
func (*CloudSchedulerClient) ResumeJob
func (c *CloudSchedulerClient) ResumeJob(ctx context.Context, req *schedulerpb.ResumeJobRequest, opts ...gax.CallOption) (*schedulerpb.Job, error)
ResumeJob 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.
Example
package main
import (
"context"
scheduler "cloud.google.com/go/scheduler/apiv1"
schedulerpb "cloud.google.com/go/scheduler/apiv1/schedulerpb"
)
func main() {
ctx := context.Background()
// 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://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := scheduler.NewCloudSchedulerClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &schedulerpb.ResumeJobRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/scheduler/apiv1/schedulerpb#ResumeJobRequest.
}
resp, err := c.ResumeJob(ctx, req)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
func (*CloudSchedulerClient) RunJob
func (c *CloudSchedulerClient) RunJob(ctx context.Context, req *schedulerpb.RunJobRequest, opts ...gax.CallOption) (*schedulerpb.Job, error)
RunJob forces a job to run now.
When this method is called, Cloud Scheduler will dispatch the job, even if the job is already running.
Example
package main
import (
"context"
scheduler "cloud.google.com/go/scheduler/apiv1"
schedulerpb "cloud.google.com/go/scheduler/apiv1/schedulerpb"
)
func main() {
ctx := context.Background()
// 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://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := scheduler.NewCloudSchedulerClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &schedulerpb.RunJobRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/scheduler/apiv1/schedulerpb#RunJobRequest.
}
resp, err := c.RunJob(ctx, req)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
func (*CloudSchedulerClient) UpdateJob
func (c *CloudSchedulerClient) UpdateJob(ctx context.Context, req *schedulerpb.UpdateJobRequest, opts ...gax.CallOption) (*schedulerpb.Job, error)
UpdateJob 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.
Example
package main
import (
"context"
scheduler "cloud.google.com/go/scheduler/apiv1"
schedulerpb "cloud.google.com/go/scheduler/apiv1/schedulerpb"
)
func main() {
ctx := context.Background()
// 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://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := scheduler.NewCloudSchedulerClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &schedulerpb.UpdateJobRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/scheduler/apiv1/schedulerpb#UpdateJobRequest.
}
resp, err := c.UpdateJob(ctx, req)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
JobIterator
type JobIterator struct {
// Response is the raw response for the current page.
// It must be cast to the RPC response type.
// Calling Next() or InternalFetch() updates this value.
Response interface{}
// InternalFetch is for use by the Google Cloud Libraries only.
// It is not part of the stable interface of this package.
//
// InternalFetch returns results from a single call to the underlying RPC.
// The number of results is no greater than pageSize.
// If there are no more results, nextPageToken is empty and err is nil.
InternalFetch func(pageSize int, pageToken string) (results []*schedulerpb.Job, nextPageToken string, err error)
// contains filtered or unexported fields
}
JobIterator manages a stream of *schedulerpb.Job.
func (*JobIterator) All
func (it *JobIterator) All() iter.Seq2[*schedulerpb.Job, error]
All returns an iterator. If an error is returned by the iterator, the iterator will stop after that iteration.
func (*JobIterator) Next
func (it *JobIterator) Next() (*schedulerpb.Job, error)
Next returns the next result. Its second return value is iterator.Done if there are no more results. Once Next returns Done, all subsequent calls will return Done.
func (*JobIterator) PageInfo
func (it *JobIterator) PageInfo() *iterator.PageInfo
PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
LocationIterator
type LocationIterator struct {
// Response is the raw response for the current page.
// It must be cast to the RPC response type.
// Calling Next() or InternalFetch() updates this value.
Response interface{}
// InternalFetch is for use by the Google Cloud Libraries only.
// It is not part of the stable interface of this package.
//
// InternalFetch returns results from a single call to the underlying RPC.
// The number of results is no greater than pageSize.
// If there are no more results, nextPageToken is empty and err is nil.
InternalFetch func(pageSize int, pageToken string) (results []*locationpb.Location, nextPageToken string, err error)
// contains filtered or unexported fields
}
LocationIterator manages a stream of *locationpb.Location.
func (*LocationIterator) All
func (it *LocationIterator) All() iter.Seq2[*locationpb.Location, error]
All returns an iterator. If an error is returned by the iterator, the iterator will stop after that iteration.
func (*LocationIterator) Next
func (it *LocationIterator) Next() (*locationpb.Location, error)
Next returns the next result. Its second return value is iterator.Done if there are no more results. Once Next returns Done, all subsequent calls will return Done.
func (*LocationIterator) PageInfo
func (it *LocationIterator) PageInfo() *iterator.PageInfo
PageInfo supports pagination. See the google.golang.org/api/iterator package for details.