Debian Codegraph @

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