Debian Codegraph @

scheduler/apiv1beta1/cloud_scheduler_client.go

raw
1 // Copyright 2025 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 // Code generated by protoc-gen-go_gapic. DO NOT EDIT.
16
17 package scheduler
18
19 import (
20 "bytes"
21 "context"
22 "fmt"
23 "log/slog"
24 "math"
25 "net/http"
26 "net/url"
27 "time"
28
29 schedulerpb "cloud.google.com/go/scheduler/apiv1beta1/schedulerpb"
30 gax "github.com/googleapis/gax-go/v2"
31 "google.golang.org/api/iterator"
32 "google.golang.org/api/option"
33 "google.golang.org/api/option/internaloption"
34 gtransport "google.golang.org/api/transport/grpc"
35 httptransport "google.golang.org/api/transport/http"
36 locationpb "google.golang.org/genproto/googleapis/cloud/location"
37 "google.golang.org/grpc"
38 "google.golang.org/grpc/codes"
39 "google.golang.org/protobuf/encoding/protojson"
40 "google.golang.org/protobuf/proto"
41 )
42
43 var newCloudSchedulerClientHook clientHook
44
45 // CloudSchedulerCallOptions contains the retry settings for each method of CloudSchedulerClient.
46 type CloudSchedulerCallOptions struct {
47 ListJobs []gax.CallOption
48 GetJob []gax.CallOption
49 CreateJob []gax.CallOption
50 UpdateJob []gax.CallOption
51 DeleteJob []gax.CallOption
52 PauseJob []gax.CallOption
53 ResumeJob []gax.CallOption
54 RunJob []gax.CallOption
55 GetLocation []gax.CallOption
56 ListLocations []gax.CallOption
57 }
58
59 func defaultCloudSchedulerGRPCClientOptions() []option.ClientOption {
60 return []option.ClientOption{
61 internaloption.WithDefaultEndpoint("cloudscheduler.googleapis.com:443"),
62 internaloption.WithDefaultEndpointTemplate("cloudscheduler.UNIVERSE_DOMAIN:443"),
63 internaloption.WithDefaultMTLSEndpoint("cloudscheduler.mtls.googleapis.com:443"),
64 internaloption.WithDefaultUniverseDomain("googleapis.com"),
65 internaloption.WithDefaultAudience("https://cloudscheduler.googleapis.com/"),
66 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
67 internaloption.EnableJwtWithScope(),
68 internaloption.EnableNewAuthLibrary(),
69 option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
70 grpc.MaxCallRecvMsgSize(math.MaxInt32))),
71 }
72 }
73
74 func defaultCloudSchedulerCallOptions() *CloudSchedulerCallOptions {
75 return &CloudSchedulerCallOptions{
76 ListJobs: []gax.CallOption{
77 gax.WithTimeout(600000 * time.Millisecond),
78 gax.WithRetry(func() gax.Retryer {
79 return gax.OnCodes([]codes.Code{
80 codes.DeadlineExceeded,
81 codes.Unavailable,
82 }, gax.Backoff{
83 Initial: 100 * time.Millisecond,
84 Max: 60000 * time.Millisecond,
85 Multiplier: 1.30,
86 })
87 }),
88 },
89 GetJob: []gax.CallOption{
90 gax.WithTimeout(600000 * time.Millisecond),
91 gax.WithRetry(func() gax.Retryer {
92 return gax.OnCodes([]codes.Code{
93 codes.DeadlineExceeded,
94 codes.Unavailable,
95 }, gax.Backoff{
96 Initial: 100 * time.Millisecond,
97 Max: 60000 * time.Millisecond,
98 Multiplier: 1.30,
99 })
100 }),
101 },
102 CreateJob: []gax.CallOption{
103 gax.WithTimeout(600000 * time.Millisecond),
104 },
105 UpdateJob: []gax.CallOption{
106 gax.WithTimeout(600000 * time.Millisecond),
107 },
108 DeleteJob: []gax.CallOption{
109 gax.WithTimeout(600000 * time.Millisecond),
110 gax.WithRetry(func() gax.Retryer {
111 return gax.OnCodes([]codes.Code{
112 codes.DeadlineExceeded,
113 codes.Unavailable,
114 }, gax.Backoff{
115 Initial: 100 * time.Millisecond,
116 Max: 60000 * time.Millisecond,
117 Multiplier: 1.30,
118 })
119 }),
120 },
121 PauseJob: []gax.CallOption{
122 gax.WithTimeout(600000 * time.Millisecond),
123 gax.WithRetry(func() gax.Retryer {
124 return gax.OnCodes([]codes.Code{
125 codes.DeadlineExceeded,
126 codes.Unavailable,
127 }, gax.Backoff{
128 Initial: 100 * time.Millisecond,
129 Max: 60000 * time.Millisecond,
130 Multiplier: 1.30,
131 })
132 }),
133 },
134 ResumeJob: []gax.CallOption{
135 gax.WithTimeout(600000 * time.Millisecond),
136 gax.WithRetry(func() gax.Retryer {
137 return gax.OnCodes([]codes.Code{
138 codes.DeadlineExceeded,
139 codes.Unavailable,
140 }, gax.Backoff{
141 Initial: 100 * time.Millisecond,
142 Max: 60000 * time.Millisecond,
143 Multiplier: 1.30,
144 })
145 }),
146 },
147 RunJob: []gax.CallOption{
148 gax.WithTimeout(600000 * time.Millisecond),
149 },
150 GetLocation: []gax.CallOption{},
151 ListLocations: []gax.CallOption{},
152 }
153 }
154
155 func defaultCloudSchedulerRESTCallOptions() *CloudSchedulerCallOptions {
156 return &CloudSchedulerCallOptions{
157 ListJobs: []gax.CallOption{
158 gax.WithTimeout(600000 * time.Millisecond),
159 gax.WithRetry(func() gax.Retryer {
160 return gax.OnHTTPCodes(gax.Backoff{
161 Initial: 100 * time.Millisecond,
162 Max: 60000 * time.Millisecond,
163 Multiplier: 1.30,
164 },
165 http.StatusGatewayTimeout,
166 http.StatusServiceUnavailable)
167 }),
168 },
169 GetJob: []gax.CallOption{
170 gax.WithTimeout(600000 * time.Millisecond),
171 gax.WithRetry(func() gax.Retryer {
172 return gax.OnHTTPCodes(gax.Backoff{
173 Initial: 100 * time.Millisecond,
174 Max: 60000 * time.Millisecond,
175 Multiplier: 1.30,
176 },
177 http.StatusGatewayTimeout,
178 http.StatusServiceUnavailable)
179 }),
180 },
181 CreateJob: []gax.CallOption{
182 gax.WithTimeout(600000 * time.Millisecond),
183 },
184 UpdateJob: []gax.CallOption{
185 gax.WithTimeout(600000 * time.Millisecond),
186 },
187 DeleteJob: []gax.CallOption{
188 gax.WithTimeout(600000 * time.Millisecond),
189 gax.WithRetry(func() gax.Retryer {
190 return gax.OnHTTPCodes(gax.Backoff{
191 Initial: 100 * time.Millisecond,
192 Max: 60000 * time.Millisecond,
193 Multiplier: 1.30,
194 },
195 http.StatusGatewayTimeout,
196 http.StatusServiceUnavailable)
197 }),
198 },
199 PauseJob: []gax.CallOption{
200 gax.WithTimeout(600000 * time.Millisecond),
201 gax.WithRetry(func() gax.Retryer {
202 return gax.OnHTTPCodes(gax.Backoff{
203 Initial: 100 * time.Millisecond,
204 Max: 60000 * time.Millisecond,
205 Multiplier: 1.30,
206 },
207 http.StatusGatewayTimeout,
208 http.StatusServiceUnavailable)
209 }),
210 },
211 ResumeJob: []gax.CallOption{
212 gax.WithTimeout(600000 * time.Millisecond),
213 gax.WithRetry(func() gax.Retryer {
214 return gax.OnHTTPCodes(gax.Backoff{
215 Initial: 100 * time.Millisecond,
216 Max: 60000 * time.Millisecond,
217 Multiplier: 1.30,
218 },
219 http.StatusGatewayTimeout,
220 http.StatusServiceUnavailable)
221 }),
222 },
223 RunJob: []gax.CallOption{
224 gax.WithTimeout(600000 * time.Millisecond),
225 },
226 GetLocation: []gax.CallOption{},
227 ListLocations: []gax.CallOption{},
228 }
229 }
230
231 // internalCloudSchedulerClient is an interface that defines the methods available from Cloud Scheduler API.
232 type internalCloudSchedulerClient interface {
233 Close() error
234 setGoogleClientInfo(...string)
235 Connection() *grpc.ClientConn
236 ListJobs(context.Context, *schedulerpb.ListJobsRequest, ...gax.CallOption) *JobIterator
237 GetJob(context.Context, *schedulerpb.GetJobRequest, ...gax.CallOption) (*schedulerpb.Job, error)
238 CreateJob(context.Context, *schedulerpb.CreateJobRequest, ...gax.CallOption) (*schedulerpb.Job, error)
239 UpdateJob(context.Context, *schedulerpb.UpdateJobRequest, ...gax.CallOption) (*schedulerpb.Job, error)
240 DeleteJob(context.Context, *schedulerpb.DeleteJobRequest, ...gax.CallOption) error
241 PauseJob(context.Context, *schedulerpb.PauseJobRequest, ...gax.CallOption) (*schedulerpb.Job, error)
242 ResumeJob(context.Context, *schedulerpb.ResumeJobRequest, ...gax.CallOption) (*schedulerpb.Job, error)
243 RunJob(context.Context, *schedulerpb.RunJobRequest, ...gax.CallOption) (*schedulerpb.Job, error)
244 GetLocation(context.Context, *locationpb.GetLocationRequest, ...gax.CallOption) (*locationpb.Location, error)
245 ListLocations(context.Context, *locationpb.ListLocationsRequest, ...gax.CallOption) *LocationIterator
246 }
247
248 // CloudSchedulerClient is a client for interacting with Cloud Scheduler API.
249 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
250 //
251 // The Cloud Scheduler API allows external entities to reliably
252 // schedule asynchronous jobs.
253 type CloudSchedulerClient struct {
254 // The internal transport-dependent client.
255 internalClient internalCloudSchedulerClient
256
257 // The call options for this service.
258 CallOptions *CloudSchedulerCallOptions
259 }
260
261 // Wrapper methods routed to the internal client.
262
263 // Close closes the connection to the API service. The user should invoke this when
264 // the client is no longer required.
265 func (c *CloudSchedulerClient) Close() error {
266 return c.internalClient.Close()
267 }
268
269 // setGoogleClientInfo sets the name and version of the application in
270 // the `x-goog-api-client` header passed on each request. Intended for
271 // use by Google-written clients.
272 func (c *CloudSchedulerClient) setGoogleClientInfo(keyval ...string) {
273 c.internalClient.setGoogleClientInfo(keyval...)
274 }
275
276 // Connection returns a connection to the API service.
277 //
278 // Deprecated: Connections are now pooled so this method does not always
279 // return the same resource.
280 func (c *CloudSchedulerClient) Connection() *grpc.ClientConn {
281 return c.internalClient.Connection()
282 }
283
284 // ListJobs lists jobs.
285 func (c *CloudSchedulerClient) ListJobs(ctx context.Context, req *schedulerpb.ListJobsRequest, opts ...gax.CallOption) *JobIterator {
286 return c.internalClient.ListJobs(ctx, req, opts...)
287 }
288
289 // GetJob gets a job.
290 func (c *CloudSchedulerClient) GetJob(ctx context.Context, req *schedulerpb.GetJobRequest, opts ...gax.CallOption) (*schedulerpb.Job, error) {
291 return c.internalClient.GetJob(ctx, req, opts...)
292 }
293
294 // CreateJob creates a job.
295 func (c *CloudSchedulerClient) CreateJob(ctx context.Context, req *schedulerpb.CreateJobRequest, opts ...gax.CallOption) (*schedulerpb.Job, error) {
296 return c.internalClient.CreateJob(ctx, req, opts...)
297 }
298
299 // UpdateJob updates a job.
300 //
301 // If successful, the updated Job is
302 // returned. If the job does not exist, NOT_FOUND is returned.
303 //
304 // If UpdateJob does not successfully return, it is possible for the
305 // job to be in an
306 // Job.State.UPDATE_FAILED
307 // state. A job in this state may not be executed. If this happens, retry the
308 // UpdateJob request until a successful response is received.
309 func (c *CloudSchedulerClient) UpdateJob(ctx context.Context, req *schedulerpb.UpdateJobRequest, opts ...gax.CallOption) (*schedulerpb.Job, error) {
310 return c.internalClient.UpdateJob(ctx, req, opts...)
311 }
312
313 // DeleteJob deletes a job.
314 func (c *CloudSchedulerClient) DeleteJob(ctx context.Context, req *schedulerpb.DeleteJobRequest, opts ...gax.CallOption) error {
315 return c.internalClient.DeleteJob(ctx, req, opts...)
316 }
317
318 // PauseJob pauses a job.
319 //
320 // If a job is paused then the system will stop executing the job
321 // until it is re-enabled via
322 // ResumeJob. The
323 // state of the job is stored in
324 // state; if paused it will be set
325 // to Job.State.PAUSED. A
326 // job must be in
327 // Job.State.ENABLED to be
328 // paused.
329 func (c *CloudSchedulerClient) PauseJob(ctx context.Context, req *schedulerpb.PauseJobRequest, opts ...gax.CallOption) (*schedulerpb.Job, error) {
330 return c.internalClient.PauseJob(ctx, req, opts...)
331 }
332
333 // ResumeJob resume a job.
334 //
335 // This method reenables a job after it has been
336 // Job.State.PAUSED. The
337 // state of a job is stored in
338 // Job.state; after calling this
339 // method it will be set to
340 // Job.State.ENABLED. A
341 // job must be in
342 // Job.State.PAUSED to be
343 // resumed.
344 func (c *CloudSchedulerClient) ResumeJob(ctx context.Context, req *schedulerpb.ResumeJobRequest, opts ...gax.CallOption) (*schedulerpb.Job, error) {
345 return c.internalClient.ResumeJob(ctx, req, opts...)
346 }
347
348 // RunJob forces a job to run now.
349 //
350 // When this method is called, Cloud Scheduler will dispatch the job, even
351 // if the job is already running.
352 func (c *CloudSchedulerClient) RunJob(ctx context.Context, req *schedulerpb.RunJobRequest, opts ...gax.CallOption) (*schedulerpb.Job, error) {
353 return c.internalClient.RunJob(ctx, req, opts...)
354 }
355
356 // GetLocation gets information about a location.
357 func (c *CloudSchedulerClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) {
358 return c.internalClient.GetLocation(ctx, req, opts...)
359 }
360
361 // ListLocations lists information about the supported locations for this service.
362 func (c *CloudSchedulerClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator {
363 return c.internalClient.ListLocations(ctx, req, opts...)
364 }
365
366 // cloudSchedulerGRPCClient is a client for interacting with Cloud Scheduler API over gRPC transport.
367 //
368 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
369 type cloudSchedulerGRPCClient struct {
370 // Connection pool of gRPC connections to the service.
371 connPool gtransport.ConnPool
372
373 // Points back to the CallOptions field of the containing CloudSchedulerClient
374 CallOptions **CloudSchedulerCallOptions
375
376 // The gRPC API client.
377 cloudSchedulerClient schedulerpb.CloudSchedulerClient
378
379 locationsClient locationpb.LocationsClient
380
381 // The x-goog-* metadata to be sent with each request.
382 xGoogHeaders []string
383
384 logger *slog.Logger
385 }
386
387 // NewCloudSchedulerClient creates a new cloud scheduler client based on gRPC.
388 // The returned client must be Closed when it is done being used to clean up its underlying connections.
389 //
390 // The Cloud Scheduler API allows external entities to reliably
391 // schedule asynchronous jobs.
392 func NewCloudSchedulerClient(ctx context.Context, opts ...option.ClientOption) (*CloudSchedulerClient, error) {
393 clientOpts := defaultCloudSchedulerGRPCClientOptions()
394 if newCloudSchedulerClientHook != nil {
395 hookOpts, err := newCloudSchedulerClientHook(ctx, clientHookParams{})
396 if err != nil {
397 return nil, err
398 }
399 clientOpts = append(clientOpts, hookOpts...)
400 }
401
402 connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
403 if err != nil {
404 return nil, err
405 }
406 client := CloudSchedulerClient{CallOptions: defaultCloudSchedulerCallOptions()}
407
408 c := &cloudSchedulerGRPCClient{
409 connPool: connPool,
410 cloudSchedulerClient: schedulerpb.NewCloudSchedulerClient(connPool),
411 CallOptions: &client.CallOptions,
412 logger: internaloption.GetLogger(opts),
413 locationsClient: locationpb.NewLocationsClient(connPool),
414 }
415 c.setGoogleClientInfo()
416
417 client.internalClient = c
418
419 return &client, nil
420 }
421
422 // Connection returns a connection to the API service.
423 //
424 // Deprecated: Connections are now pooled so this method does not always
425 // return the same resource.
426 func (c *cloudSchedulerGRPCClient) Connection() *grpc.ClientConn {
427 return c.connPool.Conn()
428 }
429
430 // setGoogleClientInfo sets the name and version of the application in
431 // the `x-goog-api-client` header passed on each request. Intended for
432 // use by Google-written clients.
433 func (c *cloudSchedulerGRPCClient) setGoogleClientInfo(keyval ...string) {
434 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
435 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion)
436 c.xGoogHeaders = []string{
437 "x-goog-api-client", gax.XGoogHeader(kv...),
438 }
439 }
440
441 // Close closes the connection to the API service. The user should invoke this when
442 // the client is no longer required.
443 func (c *cloudSchedulerGRPCClient) Close() error {
444 return c.connPool.Close()
445 }
446
447 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
448 type cloudSchedulerRESTClient struct {
449 // The http endpoint to connect to.
450 endpoint string
451
452 // The http client.
453 httpClient *http.Client
454
455 // The x-goog-* headers to be sent with each request.
456 xGoogHeaders []string
457
458 // Points back to the CallOptions field of the containing CloudSchedulerClient
459 CallOptions **CloudSchedulerCallOptions
460
461 logger *slog.Logger
462 }
463
464 // NewCloudSchedulerRESTClient creates a new cloud scheduler rest client.
465 //
466 // The Cloud Scheduler API allows external entities to reliably
467 // schedule asynchronous jobs.
468 func NewCloudSchedulerRESTClient(ctx context.Context, opts ...option.ClientOption) (*CloudSchedulerClient, error) {
469 clientOpts := append(defaultCloudSchedulerRESTClientOptions(), opts...)
470 httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...)
471 if err != nil {
472 return nil, err
473 }
474
475 callOpts := defaultCloudSchedulerRESTCallOptions()
476 c := &cloudSchedulerRESTClient{
477 endpoint: endpoint,
478 httpClient: httpClient,
479 CallOptions: &callOpts,
480 logger: internaloption.GetLogger(opts),
481 }
482 c.setGoogleClientInfo()
483
484 return &CloudSchedulerClient{internalClient: c, CallOptions: callOpts}, nil
485 }
486
487 func defaultCloudSchedulerRESTClientOptions() []option.ClientOption {
488 return []option.ClientOption{
489 internaloption.WithDefaultEndpoint("https://cloudscheduler.googleapis.com"),
490 internaloption.WithDefaultEndpointTemplate("https://cloudscheduler.UNIVERSE_DOMAIN"),
491 internaloption.WithDefaultMTLSEndpoint("https://cloudscheduler.mtls.googleapis.com"),
492 internaloption.WithDefaultUniverseDomain("googleapis.com"),
493 internaloption.WithDefaultAudience("https://cloudscheduler.googleapis.com/"),
494 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
495 internaloption.EnableNewAuthLibrary(),
496 }
497 }
498
499 // setGoogleClientInfo sets the name and version of the application in
500 // the `x-goog-api-client` header passed on each request. Intended for
501 // use by Google-written clients.
502 func (c *cloudSchedulerRESTClient) setGoogleClientInfo(keyval ...string) {
503 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
504 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN", "pb", protoVersion)
505 c.xGoogHeaders = []string{
506 "x-goog-api-client", gax.XGoogHeader(kv...),
507 }
508 }
509
510 // Close closes the connection to the API service. The user should invoke this when
511 // the client is no longer required.
512 func (c *cloudSchedulerRESTClient) Close() error {
513 // Replace httpClient with nil to force cleanup.
514 c.httpClient = nil
515 return nil
516 }
517
518 // Connection returns a connection to the API service.
519 //
520 // Deprecated: This method always returns nil.
521 func (c *cloudSchedulerRESTClient) Connection() *grpc.ClientConn {
522 return nil
523 }
524 func (c *cloudSchedulerGRPCClient) ListJobs(ctx context.Context, req *schedulerpb.ListJobsRequest, opts ...gax.CallOption) *JobIterator {
525 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
526
527 hds = append(c.xGoogHeaders, hds...)
528 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
529 opts = append((*c.CallOptions).ListJobs[0:len((*c.CallOptions).ListJobs):len((*c.CallOptions).ListJobs)], opts...)
530 it := &JobIterator{}
531 req = proto.Clone(req).(*schedulerpb.ListJobsRequest)
532 it.InternalFetch = func(pageSize int, pageToken string) ([]*schedulerpb.Job, string, error) {
533 resp := &schedulerpb.ListJobsResponse{}
534 if pageToken != "" {
535 req.PageToken = pageToken
536 }
537 if pageSize > math.MaxInt32 {
538 req.PageSize = math.MaxInt32
539 } else if pageSize != 0 {
540 req.PageSize = int32(pageSize)
541 }
542 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
543 var err error
544 resp, err = executeRPC(ctx, c.cloudSchedulerClient.ListJobs, req, settings.GRPC, c.logger, "ListJobs")
545 return err
546 }, opts...)
547 if err != nil {
548 return nil, "", err
549 }
550
551 it.Response = resp
552 return resp.GetJobs(), resp.GetNextPageToken(), nil
553 }
554 fetch := func(pageSize int, pageToken string) (string, error) {
555 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
556 if err != nil {
557 return "", err
558 }
559 it.items = append(it.items, items...)
560 return nextPageToken, nil
561 }
562
563 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
564 it.pageInfo.MaxSize = int(req.GetPageSize())
565 it.pageInfo.Token = req.GetPageToken()
566
567 return it
568 }
569
570 func (c *cloudSchedulerGRPCClient) GetJob(ctx context.Context, req *schedulerpb.GetJobRequest, opts ...gax.CallOption) (*schedulerpb.Job, error) {
571 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
572
573 hds = append(c.xGoogHeaders, hds...)
574 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
575 opts = append((*c.CallOptions).GetJob[0:len((*c.CallOptions).GetJob):len((*c.CallOptions).GetJob)], opts...)
576 var resp *schedulerpb.Job
577 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
578 var err error
579 resp, err = executeRPC(ctx, c.cloudSchedulerClient.GetJob, req, settings.GRPC, c.logger, "GetJob")
580 return err
581 }, opts...)
582 if err != nil {
583 return nil, err
584 }
585 return resp, nil
586 }
587
588 func (c *cloudSchedulerGRPCClient) CreateJob(ctx context.Context, req *schedulerpb.CreateJobRequest, opts ...gax.CallOption) (*schedulerpb.Job, error) {
589 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
590
591 hds = append(c.xGoogHeaders, hds...)
592 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
593 opts = append((*c.CallOptions).CreateJob[0:len((*c.CallOptions).CreateJob):len((*c.CallOptions).CreateJob)], opts...)
594 var resp *schedulerpb.Job
595 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
596 var err error
597 resp, err = executeRPC(ctx, c.cloudSchedulerClient.CreateJob, req, settings.GRPC, c.logger, "CreateJob")
598 return err
599 }, opts...)
600 if err != nil {
601 return nil, err
602 }
603 return resp, nil
604 }
605
606 func (c *cloudSchedulerGRPCClient) UpdateJob(ctx context.Context, req *schedulerpb.UpdateJobRequest, opts ...gax.CallOption) (*schedulerpb.Job, error) {
607 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "job.name", url.QueryEscape(req.GetJob().GetName()))}
608
609 hds = append(c.xGoogHeaders, hds...)
610 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
611 opts = append((*c.CallOptions).UpdateJob[0:len((*c.CallOptions).UpdateJob):len((*c.CallOptions).UpdateJob)], opts...)
612 var resp *schedulerpb.Job
613 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
614 var err error
615 resp, err = executeRPC(ctx, c.cloudSchedulerClient.UpdateJob, req, settings.GRPC, c.logger, "UpdateJob")
616 return err
617 }, opts...)
618 if err != nil {
619 return nil, err
620 }
621 return resp, nil
622 }
623
624 func (c *cloudSchedulerGRPCClient) DeleteJob(ctx context.Context, req *schedulerpb.DeleteJobRequest, opts ...gax.CallOption) error {
625 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
626
627 hds = append(c.xGoogHeaders, hds...)
628 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
629 opts = append((*c.CallOptions).DeleteJob[0:len((*c.CallOptions).DeleteJob):len((*c.CallOptions).DeleteJob)], opts...)
630 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
631 var err error
632 _, err = executeRPC(ctx, c.cloudSchedulerClient.DeleteJob, req, settings.GRPC, c.logger, "DeleteJob")
633 return err
634 }, opts...)
635 return err
636 }
637
638 func (c *cloudSchedulerGRPCClient) PauseJob(ctx context.Context, req *schedulerpb.PauseJobRequest, opts ...gax.CallOption) (*schedulerpb.Job, error) {
639 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
640
641 hds = append(c.xGoogHeaders, hds...)
642 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
643 opts = append((*c.CallOptions).PauseJob[0:len((*c.CallOptions).PauseJob):len((*c.CallOptions).PauseJob)], opts...)
644 var resp *schedulerpb.Job
645 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
646 var err error
647 resp, err = executeRPC(ctx, c.cloudSchedulerClient.PauseJob, req, settings.GRPC, c.logger, "PauseJob")
648 return err
649 }, opts...)
650 if err != nil {
651 return nil, err
652 }
653 return resp, nil
654 }
655
656 func (c *cloudSchedulerGRPCClient) ResumeJob(ctx context.Context, req *schedulerpb.ResumeJobRequest, opts ...gax.CallOption) (*schedulerpb.Job, error) {
657 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
658
659 hds = append(c.xGoogHeaders, hds...)
660 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
661 opts = append((*c.CallOptions).ResumeJob[0:len((*c.CallOptions).ResumeJob):len((*c.CallOptions).ResumeJob)], opts...)
662 var resp *schedulerpb.Job
663 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
664 var err error
665 resp, err = executeRPC(ctx, c.cloudSchedulerClient.ResumeJob, req, settings.GRPC, c.logger, "ResumeJob")
666 return err
667 }, opts...)
668 if err != nil {
669 return nil, err
670 }
671 return resp, nil
672 }
673
674 func (c *cloudSchedulerGRPCClient) RunJob(ctx context.Context, req *schedulerpb.RunJobRequest, opts ...gax.CallOption) (*schedulerpb.Job, error) {
675 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
676
677 hds = append(c.xGoogHeaders, hds...)
678 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
679 opts = append((*c.CallOptions).RunJob[0:len((*c.CallOptions).RunJob):len((*c.CallOptions).RunJob)], opts...)
680 var resp *schedulerpb.Job
681 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
682 var err error
683 resp, err = executeRPC(ctx, c.cloudSchedulerClient.RunJob, req, settings.GRPC, c.logger, "RunJob")
684 return err
685 }, opts...)
686 if err != nil {
687 return nil, err
688 }
689 return resp, nil
690 }
691
692 func (c *cloudSchedulerGRPCClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) {
693 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
694
695 hds = append(c.xGoogHeaders, hds...)
696 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
697 opts = append((*c.CallOptions).GetLocation[0:len((*c.CallOptions).GetLocation):len((*c.CallOptions).GetLocation)], opts...)
698 var resp *locationpb.Location
699 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
700 var err error
701 resp, err = executeRPC(ctx, c.locationsClient.GetLocation, req, settings.GRPC, c.logger, "GetLocation")
702 return err
703 }, opts...)
704 if err != nil {
705 return nil, err
706 }
707 return resp, nil
708 }
709
710 func (c *cloudSchedulerGRPCClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator {
711 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
712
713 hds = append(c.xGoogHeaders, hds...)
714 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
715 opts = append((*c.CallOptions).ListLocations[0:len((*c.CallOptions).ListLocations):len((*c.CallOptions).ListLocations)], opts...)
716 it := &LocationIterator{}
717 req = proto.Clone(req).(*locationpb.ListLocationsRequest)
718 it.InternalFetch = func(pageSize int, pageToken string) ([]*locationpb.Location, string, error) {
719 resp := &locationpb.ListLocationsResponse{}
720 if pageToken != "" {
721 req.PageToken = pageToken
722 }
723 if pageSize > math.MaxInt32 {
724 req.PageSize = math.MaxInt32
725 } else if pageSize != 0 {
726 req.PageSize = int32(pageSize)
727 }
728 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
729 var err error
730 resp, err = executeRPC(ctx, c.locationsClient.ListLocations, req, settings.GRPC, c.logger, "ListLocations")
731 return err
732 }, opts...)
733 if err != nil {
734 return nil, "", err
735 }
736
737 it.Response = resp
738 return resp.GetLocations(), resp.GetNextPageToken(), nil
739 }
740 fetch := func(pageSize int, pageToken string) (string, error) {
741 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
742 if err != nil {
743 return "", err
744 }
745 it.items = append(it.items, items...)
746 return nextPageToken, nil
747 }
748
749 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
750 it.pageInfo.MaxSize = int(req.GetPageSize())
751 it.pageInfo.Token = req.GetPageToken()
752
753 return it
754 }
755
756 // ListJobs lists jobs.
757 func (c *cloudSchedulerRESTClient) ListJobs(ctx context.Context, req *schedulerpb.ListJobsRequest, opts ...gax.CallOption) *JobIterator {
758 it := &JobIterator{}
759 req = proto.Clone(req).(*schedulerpb.ListJobsRequest)
760 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
761 it.InternalFetch = func(pageSize int, pageToken string) ([]*schedulerpb.Job, string, error) {
762 resp := &schedulerpb.ListJobsResponse{}
763 if pageToken != "" {
764 req.PageToken = pageToken
765 }
766 if pageSize > math.MaxInt32 {
767 req.PageSize = math.MaxInt32
768 } else if pageSize != 0 {
769 req.PageSize = int32(pageSize)
770 }
771 baseUrl, err := url.Parse(c.endpoint)
772 if err != nil {
773 return nil, "", err
774 }
775 baseUrl.Path += fmt.Sprintf("/v1beta1/%v/jobs", req.GetParent())
776
777 params := url.Values{}
778 params.Add("$alt", "json;enum-encoding=int")
779 if req.GetFilter() != "" {
780 params.Add("filter", fmt.Sprintf("%v", req.GetFilter()))
781 }
782 if req.GetLegacyAppEngineCron() {
783 params.Add("legacyAppEngineCron", fmt.Sprintf("%v", req.GetLegacyAppEngineCron()))
784 }
785 if req.GetPageSize() != 0 {
786 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
787 }
788 if req.GetPageToken() != "" {
789 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
790 }
791
792 baseUrl.RawQuery = params.Encode()
793
794 // Build HTTP headers from client and context metadata.
795 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
796 headers := gax.BuildHeaders(ctx, hds...)
797 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
798 if settings.Path != "" {
799 baseUrl.Path = settings.Path
800 }
801 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
802 if err != nil {
803 return err
804 }
805 httpReq.Header = headers
806
807 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListJobs")
808 if err != nil {
809 return err
810 }
811 if err := unm.Unmarshal(buf, resp); err != nil {
812 return err
813 }
814
815 return nil
816 }, opts...)
817 if e != nil {
818 return nil, "", e
819 }
820 it.Response = resp
821 return resp.GetJobs(), resp.GetNextPageToken(), nil
822 }
823
824 fetch := func(pageSize int, pageToken string) (string, error) {
825 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
826 if err != nil {
827 return "", err
828 }
829 it.items = append(it.items, items...)
830 return nextPageToken, nil
831 }
832
833 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
834 it.pageInfo.MaxSize = int(req.GetPageSize())
835 it.pageInfo.Token = req.GetPageToken()
836
837 return it
838 }
839
840 // GetJob gets a job.
841 func (c *cloudSchedulerRESTClient) GetJob(ctx context.Context, req *schedulerpb.GetJobRequest, opts ...gax.CallOption) (*schedulerpb.Job, error) {
842 baseUrl, err := url.Parse(c.endpoint)
843 if err != nil {
844 return nil, err
845 }
846 baseUrl.Path += fmt.Sprintf("/v1beta1/%v", req.GetName())
847
848 params := url.Values{}
849 params.Add("$alt", "json;enum-encoding=int")
850
851 baseUrl.RawQuery = params.Encode()
852
853 // Build HTTP headers from client and context metadata.
854 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
855
856 hds = append(c.xGoogHeaders, hds...)
857 hds = append(hds, "Content-Type", "application/json")
858 headers := gax.BuildHeaders(ctx, hds...)
859 opts = append((*c.CallOptions).GetJob[0:len((*c.CallOptions).GetJob):len((*c.CallOptions).GetJob)], opts...)
860 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
861 resp := &schedulerpb.Job{}
862 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
863 if settings.Path != "" {
864 baseUrl.Path = settings.Path
865 }
866 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
867 if err != nil {
868 return err
869 }
870 httpReq = httpReq.WithContext(ctx)
871 httpReq.Header = headers
872
873 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetJob")
874 if err != nil {
875 return err
876 }
877
878 if err := unm.Unmarshal(buf, resp); err != nil {
879 return err
880 }
881
882 return nil
883 }, opts...)
884 if e != nil {
885 return nil, e
886 }
887 return resp, nil
888 }
889
890 // CreateJob creates a job.
891 func (c *cloudSchedulerRESTClient) CreateJob(ctx context.Context, req *schedulerpb.CreateJobRequest, opts ...gax.CallOption) (*schedulerpb.Job, error) {
892 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
893 body := req.GetJob()
894 jsonReq, err := m.Marshal(body)
895 if err != nil {
896 return nil, err
897 }
898
899 baseUrl, err := url.Parse(c.endpoint)
900 if err != nil {
901 return nil, err
902 }
903 baseUrl.Path += fmt.Sprintf("/v1beta1/%v/jobs", req.GetParent())
904
905 params := url.Values{}
906 params.Add("$alt", "json;enum-encoding=int")
907
908 baseUrl.RawQuery = params.Encode()
909
910 // Build HTTP headers from client and context metadata.
911 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
912
913 hds = append(c.xGoogHeaders, hds...)
914 hds = append(hds, "Content-Type", "application/json")
915 headers := gax.BuildHeaders(ctx, hds...)
916 opts = append((*c.CallOptions).CreateJob[0:len((*c.CallOptions).CreateJob):len((*c.CallOptions).CreateJob)], opts...)
917 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
918 resp := &schedulerpb.Job{}
919 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
920 if settings.Path != "" {
921 baseUrl.Path = settings.Path
922 }
923 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
924 if err != nil {
925 return err
926 }
927 httpReq = httpReq.WithContext(ctx)
928 httpReq.Header = headers
929
930 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CreateJob")
931 if err != nil {
932 return err
933 }
934
935 if err := unm.Unmarshal(buf, resp); err != nil {
936 return err
937 }
938
939 return nil
940 }, opts...)
941 if e != nil {
942 return nil, e
943 }
944 return resp, nil
945 }
946
947 // UpdateJob updates a job.
948 //
949 // If successful, the updated Job is
950 // returned. If the job does not exist, NOT_FOUND is returned.
951 //
952 // If UpdateJob does not successfully return, it is possible for the
953 // job to be in an
954 // Job.State.UPDATE_FAILED
955 // state. A job in this state may not be executed. If this happens, retry the
956 // UpdateJob request until a successful response is received.
957 func (c *cloudSchedulerRESTClient) UpdateJob(ctx context.Context, req *schedulerpb.UpdateJobRequest, opts ...gax.CallOption) (*schedulerpb.Job, error) {
958 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
959 body := req.GetJob()
960 jsonReq, err := m.Marshal(body)
961 if err != nil {
962 return nil, err
963 }
964
965 baseUrl, err := url.Parse(c.endpoint)
966 if err != nil {
967 return nil, err
968 }
969 baseUrl.Path += fmt.Sprintf("/v1beta1/%v", req.GetJob().GetName())
970
971 params := url.Values{}
972 params.Add("$alt", "json;enum-encoding=int")
973 if req.GetUpdateMask() != nil {
974 field, err := protojson.Marshal(req.GetUpdateMask())
975 if err != nil {
976 return nil, err
977 }
978 params.Add("updateMask", string(field[1:len(field)-1]))
979 }
980
981 baseUrl.RawQuery = params.Encode()
982
983 // Build HTTP headers from client and context metadata.
984 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "job.name", url.QueryEscape(req.GetJob().GetName()))}
985
986 hds = append(c.xGoogHeaders, hds...)
987 hds = append(hds, "Content-Type", "application/json")
988 headers := gax.BuildHeaders(ctx, hds...)
989 opts = append((*c.CallOptions).UpdateJob[0:len((*c.CallOptions).UpdateJob):len((*c.CallOptions).UpdateJob)], opts...)
990 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
991 resp := &schedulerpb.Job{}
992 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
993 if settings.Path != "" {
994 baseUrl.Path = settings.Path
995 }
996 httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq))
997 if err != nil {
998 return err
999 }
1000 httpReq = httpReq.WithContext(ctx)
1001 httpReq.Header = headers
1002
1003 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "UpdateJob")
1004 if err != nil {
1005 return err
1006 }
1007
1008 if err := unm.Unmarshal(buf, resp); err != nil {
1009 return err
1010 }
1011
1012 return nil
1013 }, opts...)
1014 if e != nil {
1015 return nil, e
1016 }
1017 return resp, nil
1018 }
1019
1020 // DeleteJob deletes a job.
1021 func (c *cloudSchedulerRESTClient) DeleteJob(ctx context.Context, req *schedulerpb.DeleteJobRequest, opts ...gax.CallOption) error {
1022 baseUrl, err := url.Parse(c.endpoint)
1023 if err != nil {
1024 return err
1025 }
1026 baseUrl.Path += fmt.Sprintf("/v1beta1/%v", req.GetName())
1027
1028 params := url.Values{}
1029 params.Add("$alt", "json;enum-encoding=int")
1030 if req.GetLegacyAppEngineCron() {
1031 params.Add("legacyAppEngineCron", fmt.Sprintf("%v", req.GetLegacyAppEngineCron()))
1032 }
1033
1034 baseUrl.RawQuery = params.Encode()
1035
1036 // Build HTTP headers from client and context metadata.
1037 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1038
1039 hds = append(c.xGoogHeaders, hds...)
1040 hds = append(hds, "Content-Type", "application/json")
1041 headers := gax.BuildHeaders(ctx, hds...)
1042 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1043 if settings.Path != "" {
1044 baseUrl.Path = settings.Path
1045 }
1046 httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil)
1047 if err != nil {
1048 return err
1049 }
1050 httpReq = httpReq.WithContext(ctx)
1051 httpReq.Header = headers
1052
1053 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteJob")
1054 return err
1055 }, opts...)
1056 }
1057
1058 // PauseJob pauses a job.
1059 //
1060 // If a job is paused then the system will stop executing the job
1061 // until it is re-enabled via
1062 // ResumeJob. The
1063 // state of the job is stored in
1064 // state; if paused it will be set
1065 // to Job.State.PAUSED. A
1066 // job must be in
1067 // Job.State.ENABLED to be
1068 // paused.
1069 func (c *cloudSchedulerRESTClient) PauseJob(ctx context.Context, req *schedulerpb.PauseJobRequest, opts ...gax.CallOption) (*schedulerpb.Job, error) {
1070 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
1071 jsonReq, err := m.Marshal(req)
1072 if err != nil {
1073 return nil, err
1074 }
1075
1076 baseUrl, err := url.Parse(c.endpoint)
1077 if err != nil {
1078 return nil, err
1079 }
1080 baseUrl.Path += fmt.Sprintf("/v1beta1/%v:pause", req.GetName())
1081
1082 params := url.Values{}
1083 params.Add("$alt", "json;enum-encoding=int")
1084
1085 baseUrl.RawQuery = params.Encode()
1086
1087 // Build HTTP headers from client and context metadata.
1088 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1089
1090 hds = append(c.xGoogHeaders, hds...)
1091 hds = append(hds, "Content-Type", "application/json")
1092 headers := gax.BuildHeaders(ctx, hds...)
1093 opts = append((*c.CallOptions).PauseJob[0:len((*c.CallOptions).PauseJob):len((*c.CallOptions).PauseJob)], opts...)
1094 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1095 resp := &schedulerpb.Job{}
1096 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1097 if settings.Path != "" {
1098 baseUrl.Path = settings.Path
1099 }
1100 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
1101 if err != nil {
1102 return err
1103 }
1104 httpReq = httpReq.WithContext(ctx)
1105 httpReq.Header = headers
1106
1107 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "PauseJob")
1108 if err != nil {
1109 return err
1110 }
1111
1112 if err := unm.Unmarshal(buf, resp); err != nil {
1113 return err
1114 }
1115
1116 return nil
1117 }, opts...)
1118 if e != nil {
1119 return nil, e
1120 }
1121 return resp, nil
1122 }
1123
1124 // ResumeJob resume a job.
1125 //
1126 // This method reenables a job after it has been
1127 // Job.State.PAUSED. The
1128 // state of a job is stored in
1129 // Job.state; after calling this
1130 // method it will be set to
1131 // Job.State.ENABLED. A
1132 // job must be in
1133 // Job.State.PAUSED to be
1134 // resumed.
1135 func (c *cloudSchedulerRESTClient) ResumeJob(ctx context.Context, req *schedulerpb.ResumeJobRequest, opts ...gax.CallOption) (*schedulerpb.Job, error) {
1136 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
1137 jsonReq, err := m.Marshal(req)
1138 if err != nil {
1139 return nil, err
1140 }
1141
1142 baseUrl, err := url.Parse(c.endpoint)
1143 if err != nil {
1144 return nil, err
1145 }
1146 baseUrl.Path += fmt.Sprintf("/v1beta1/%v:resume", req.GetName())
1147
1148 params := url.Values{}
1149 params.Add("$alt", "json;enum-encoding=int")
1150
1151 baseUrl.RawQuery = params.Encode()
1152
1153 // Build HTTP headers from client and context metadata.
1154 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1155
1156 hds = append(c.xGoogHeaders, hds...)
1157 hds = append(hds, "Content-Type", "application/json")
1158 headers := gax.BuildHeaders(ctx, hds...)
1159 opts = append((*c.CallOptions).ResumeJob[0:len((*c.CallOptions).ResumeJob):len((*c.CallOptions).ResumeJob)], opts...)
1160 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1161 resp := &schedulerpb.Job{}
1162 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1163 if settings.Path != "" {
1164 baseUrl.Path = settings.Path
1165 }
1166 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
1167 if err != nil {
1168 return err
1169 }
1170 httpReq = httpReq.WithContext(ctx)
1171 httpReq.Header = headers
1172
1173 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "ResumeJob")
1174 if err != nil {
1175 return err
1176 }
1177
1178 if err := unm.Unmarshal(buf, resp); err != nil {
1179 return err
1180 }
1181
1182 return nil
1183 }, opts...)
1184 if e != nil {
1185 return nil, e
1186 }
1187 return resp, nil
1188 }
1189
1190 // RunJob forces a job to run now.
1191 //
1192 // When this method is called, Cloud Scheduler will dispatch the job, even
1193 // if the job is already running.
1194 func (c *cloudSchedulerRESTClient) RunJob(ctx context.Context, req *schedulerpb.RunJobRequest, opts ...gax.CallOption) (*schedulerpb.Job, error) {
1195 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
1196 jsonReq, err := m.Marshal(req)
1197 if err != nil {
1198 return nil, err
1199 }
1200
1201 baseUrl, err := url.Parse(c.endpoint)
1202 if err != nil {
1203 return nil, err
1204 }
1205 baseUrl.Path += fmt.Sprintf("/v1beta1/%v:run", req.GetName())
1206
1207 params := url.Values{}
1208 params.Add("$alt", "json;enum-encoding=int")
1209
1210 baseUrl.RawQuery = params.Encode()
1211
1212 // Build HTTP headers from client and context metadata.
1213 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1214
1215 hds = append(c.xGoogHeaders, hds...)
1216 hds = append(hds, "Content-Type", "application/json")
1217 headers := gax.BuildHeaders(ctx, hds...)
1218 opts = append((*c.CallOptions).RunJob[0:len((*c.CallOptions).RunJob):len((*c.CallOptions).RunJob)], opts...)
1219 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1220 resp := &schedulerpb.Job{}
1221 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1222 if settings.Path != "" {
1223 baseUrl.Path = settings.Path
1224 }
1225 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
1226 if err != nil {
1227 return err
1228 }
1229 httpReq = httpReq.WithContext(ctx)
1230 httpReq.Header = headers
1231
1232 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "RunJob")
1233 if err != nil {
1234 return err
1235 }
1236
1237 if err := unm.Unmarshal(buf, resp); err != nil {
1238 return err
1239 }
1240
1241 return nil
1242 }, opts...)
1243 if e != nil {
1244 return nil, e
1245 }
1246 return resp, nil
1247 }
1248
1249 // GetLocation gets information about a location.
1250 func (c *cloudSchedulerRESTClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) {
1251 baseUrl, err := url.Parse(c.endpoint)
1252 if err != nil {
1253 return nil, err
1254 }
1255 baseUrl.Path += fmt.Sprintf("/v1beta1/%v", req.GetName())
1256
1257 params := url.Values{}
1258 params.Add("$alt", "json;enum-encoding=int")
1259
1260 baseUrl.RawQuery = params.Encode()
1261
1262 // Build HTTP headers from client and context metadata.
1263 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1264
1265 hds = append(c.xGoogHeaders, hds...)
1266 hds = append(hds, "Content-Type", "application/json")
1267 headers := gax.BuildHeaders(ctx, hds...)
1268 opts = append((*c.CallOptions).GetLocation[0:len((*c.CallOptions).GetLocation):len((*c.CallOptions).GetLocation)], opts...)
1269 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1270 resp := &locationpb.Location{}
1271 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1272 if settings.Path != "" {
1273 baseUrl.Path = settings.Path
1274 }
1275 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
1276 if err != nil {
1277 return err
1278 }
1279 httpReq = httpReq.WithContext(ctx)
1280 httpReq.Header = headers
1281
1282 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetLocation")
1283 if err != nil {
1284 return err
1285 }
1286
1287 if err := unm.Unmarshal(buf, resp); err != nil {
1288 return err
1289 }
1290
1291 return nil
1292 }, opts...)
1293 if e != nil {
1294 return nil, e
1295 }
1296 return resp, nil
1297 }
1298
1299 // ListLocations lists information about the supported locations for this service.
1300 func (c *cloudSchedulerRESTClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator {
1301 it := &LocationIterator{}
1302 req = proto.Clone(req).(*locationpb.ListLocationsRequest)
1303 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1304 it.InternalFetch = func(pageSize int, pageToken string) ([]*locationpb.Location, string, error) {
1305 resp := &locationpb.ListLocationsResponse{}
1306 if pageToken != "" {
1307 req.PageToken = pageToken
1308 }
1309 if pageSize > math.MaxInt32 {
1310 req.PageSize = math.MaxInt32
1311 } else if pageSize != 0 {
1312 req.PageSize = int32(pageSize)
1313 }
1314 baseUrl, err := url.Parse(c.endpoint)
1315 if err != nil {
1316 return nil, "", err
1317 }
1318 baseUrl.Path += fmt.Sprintf("/v1beta1/%v/locations", req.GetName())
1319
1320 params := url.Values{}
1321 params.Add("$alt", "json;enum-encoding=int")
1322 if req.GetFilter() != "" {
1323 params.Add("filter", fmt.Sprintf("%v", req.GetFilter()))
1324 }
1325 if req.GetPageSize() != 0 {
1326 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
1327 }
1328 if req.GetPageToken() != "" {
1329 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
1330 }
1331
1332 baseUrl.RawQuery = params.Encode()
1333
1334 // Build HTTP headers from client and context metadata.
1335 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
1336 headers := gax.BuildHeaders(ctx, hds...)
1337 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1338 if settings.Path != "" {
1339 baseUrl.Path = settings.Path
1340 }
1341 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
1342 if err != nil {
1343 return err
1344 }
1345 httpReq.Header = headers
1346
1347 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListLocations")
1348 if err != nil {
1349 return err
1350 }
1351 if err := unm.Unmarshal(buf, resp); err != nil {
1352 return err
1353 }
1354
1355 return nil
1356 }, opts...)
1357 if e != nil {
1358 return nil, "", e
1359 }
1360 it.Response = resp
1361 return resp.GetLocations(), resp.GetNextPageToken(), nil
1362 }
1363
1364 fetch := func(pageSize int, pageToken string) (string, error) {
1365 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
1366 if err != nil {
1367 return "", err
1368 }
1369 it.items = append(it.items, items...)
1370 return nextPageToken, nil
1371 }
1372
1373 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
1374 it.pageInfo.MaxSize = int(req.GetPageSize())
1375 it.pageInfo.Token = req.GetPageToken()
1376
1377 return it
1378 }