Debian Codegraph @

talent/apiv4beta1/job_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 talent
18
19 import (
20 "bytes"
21 "context"
22 "fmt"
23 "log/slog"
24 "math"
25 "net/http"
26 "net/url"
27 "time"
28
29 "cloud.google.com/go/longrunning"
30 lroauto "cloud.google.com/go/longrunning/autogen"
31 longrunningpb "cloud.google.com/go/longrunning/autogen/longrunningpb"
32 talentpb "cloud.google.com/go/talent/apiv4beta1/talentpb"
33 gax "github.com/googleapis/gax-go/v2"
34 "google.golang.org/api/iterator"
35 "google.golang.org/api/option"
36 "google.golang.org/api/option/internaloption"
37 gtransport "google.golang.org/api/transport/grpc"
38 httptransport "google.golang.org/api/transport/http"
39 "google.golang.org/grpc"
40 "google.golang.org/grpc/codes"
41 "google.golang.org/protobuf/encoding/protojson"
42 "google.golang.org/protobuf/proto"
43 )
44
45 var newJobClientHook clientHook
46
47 // JobCallOptions contains the retry settings for each method of JobClient.
48 type JobCallOptions struct {
49 CreateJob []gax.CallOption
50 BatchCreateJobs []gax.CallOption
51 GetJob []gax.CallOption
52 UpdateJob []gax.CallOption
53 BatchUpdateJobs []gax.CallOption
54 DeleteJob []gax.CallOption
55 BatchDeleteJobs []gax.CallOption
56 ListJobs []gax.CallOption
57 SearchJobs []gax.CallOption
58 SearchJobsForAlert []gax.CallOption
59 GetOperation []gax.CallOption
60 }
61
62 func defaultJobGRPCClientOptions() []option.ClientOption {
63 return []option.ClientOption{
64 internaloption.WithDefaultEndpoint("jobs.googleapis.com:443"),
65 internaloption.WithDefaultEndpointTemplate("jobs.UNIVERSE_DOMAIN:443"),
66 internaloption.WithDefaultMTLSEndpoint("jobs.mtls.googleapis.com:443"),
67 internaloption.WithDefaultUniverseDomain("googleapis.com"),
68 internaloption.WithDefaultAudience("https://jobs.googleapis.com/"),
69 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
70 internaloption.EnableJwtWithScope(),
71 internaloption.EnableNewAuthLibrary(),
72 option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
73 grpc.MaxCallRecvMsgSize(math.MaxInt32))),
74 }
75 }
76
77 func defaultJobCallOptions() *JobCallOptions {
78 return &JobCallOptions{
79 CreateJob: []gax.CallOption{
80 gax.WithTimeout(30000 * time.Millisecond),
81 },
82 BatchCreateJobs: []gax.CallOption{
83 gax.WithTimeout(30000 * time.Millisecond),
84 },
85 GetJob: []gax.CallOption{
86 gax.WithTimeout(30000 * time.Millisecond),
87 gax.WithRetry(func() gax.Retryer {
88 return gax.OnCodes([]codes.Code{
89 codes.DeadlineExceeded,
90 codes.Unavailable,
91 }, gax.Backoff{
92 Initial: 100 * time.Millisecond,
93 Max: 60000 * time.Millisecond,
94 Multiplier: 1.30,
95 })
96 }),
97 },
98 UpdateJob: []gax.CallOption{
99 gax.WithTimeout(30000 * time.Millisecond),
100 },
101 BatchUpdateJobs: []gax.CallOption{
102 gax.WithTimeout(30000 * time.Millisecond),
103 },
104 DeleteJob: []gax.CallOption{
105 gax.WithTimeout(30000 * time.Millisecond),
106 gax.WithRetry(func() gax.Retryer {
107 return gax.OnCodes([]codes.Code{
108 codes.DeadlineExceeded,
109 codes.Unavailable,
110 }, gax.Backoff{
111 Initial: 100 * time.Millisecond,
112 Max: 60000 * time.Millisecond,
113 Multiplier: 1.30,
114 })
115 }),
116 },
117 BatchDeleteJobs: []gax.CallOption{
118 gax.WithTimeout(30000 * time.Millisecond),
119 },
120 ListJobs: []gax.CallOption{
121 gax.WithTimeout(30000 * time.Millisecond),
122 gax.WithRetry(func() gax.Retryer {
123 return gax.OnCodes([]codes.Code{
124 codes.DeadlineExceeded,
125 codes.Unavailable,
126 }, gax.Backoff{
127 Initial: 100 * time.Millisecond,
128 Max: 60000 * time.Millisecond,
129 Multiplier: 1.30,
130 })
131 }),
132 },
133 SearchJobs: []gax.CallOption{
134 gax.WithTimeout(30000 * time.Millisecond),
135 },
136 SearchJobsForAlert: []gax.CallOption{
137 gax.WithTimeout(30000 * time.Millisecond),
138 },
139 GetOperation: []gax.CallOption{},
140 }
141 }
142
143 func defaultJobRESTCallOptions() *JobCallOptions {
144 return &JobCallOptions{
145 CreateJob: []gax.CallOption{
146 gax.WithTimeout(30000 * time.Millisecond),
147 },
148 BatchCreateJobs: []gax.CallOption{
149 gax.WithTimeout(30000 * time.Millisecond),
150 },
151 GetJob: []gax.CallOption{
152 gax.WithTimeout(30000 * time.Millisecond),
153 gax.WithRetry(func() gax.Retryer {
154 return gax.OnHTTPCodes(gax.Backoff{
155 Initial: 100 * time.Millisecond,
156 Max: 60000 * time.Millisecond,
157 Multiplier: 1.30,
158 },
159 http.StatusGatewayTimeout,
160 http.StatusServiceUnavailable)
161 }),
162 },
163 UpdateJob: []gax.CallOption{
164 gax.WithTimeout(30000 * time.Millisecond),
165 },
166 BatchUpdateJobs: []gax.CallOption{
167 gax.WithTimeout(30000 * time.Millisecond),
168 },
169 DeleteJob: []gax.CallOption{
170 gax.WithTimeout(30000 * 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 BatchDeleteJobs: []gax.CallOption{
182 gax.WithTimeout(30000 * time.Millisecond),
183 },
184 ListJobs: []gax.CallOption{
185 gax.WithTimeout(30000 * time.Millisecond),
186 gax.WithRetry(func() gax.Retryer {
187 return gax.OnHTTPCodes(gax.Backoff{
188 Initial: 100 * time.Millisecond,
189 Max: 60000 * time.Millisecond,
190 Multiplier: 1.30,
191 },
192 http.StatusGatewayTimeout,
193 http.StatusServiceUnavailable)
194 }),
195 },
196 SearchJobs: []gax.CallOption{
197 gax.WithTimeout(30000 * time.Millisecond),
198 },
199 SearchJobsForAlert: []gax.CallOption{
200 gax.WithTimeout(30000 * time.Millisecond),
201 },
202 GetOperation: []gax.CallOption{},
203 }
204 }
205
206 // internalJobClient is an interface that defines the methods available from Cloud Talent Solution API.
207 type internalJobClient interface {
208 Close() error
209 setGoogleClientInfo(...string)
210 Connection() *grpc.ClientConn
211 CreateJob(context.Context, *talentpb.CreateJobRequest, ...gax.CallOption) (*talentpb.Job, error)
212 BatchCreateJobs(context.Context, *talentpb.BatchCreateJobsRequest, ...gax.CallOption) (*BatchCreateJobsOperation, error)
213 BatchCreateJobsOperation(name string) *BatchCreateJobsOperation
214 GetJob(context.Context, *talentpb.GetJobRequest, ...gax.CallOption) (*talentpb.Job, error)
215 UpdateJob(context.Context, *talentpb.UpdateJobRequest, ...gax.CallOption) (*talentpb.Job, error)
216 BatchUpdateJobs(context.Context, *talentpb.BatchUpdateJobsRequest, ...gax.CallOption) (*BatchUpdateJobsOperation, error)
217 BatchUpdateJobsOperation(name string) *BatchUpdateJobsOperation
218 DeleteJob(context.Context, *talentpb.DeleteJobRequest, ...gax.CallOption) error
219 BatchDeleteJobs(context.Context, *talentpb.BatchDeleteJobsRequest, ...gax.CallOption) error
220 ListJobs(context.Context, *talentpb.ListJobsRequest, ...gax.CallOption) *JobIterator
221 SearchJobs(context.Context, *talentpb.SearchJobsRequest, ...gax.CallOption) (*talentpb.SearchJobsResponse, error)
222 SearchJobsForAlert(context.Context, *talentpb.SearchJobsRequest, ...gax.CallOption) *SearchJobsResponse_MatchingJobIterator
223 GetOperation(context.Context, *longrunningpb.GetOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error)
224 }
225
226 // JobClient is a client for interacting with Cloud Talent Solution API.
227 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
228 //
229 // A service handles job management, including job CRUD, enumeration and search.
230 type JobClient struct {
231 // The internal transport-dependent client.
232 internalClient internalJobClient
233
234 // The call options for this service.
235 CallOptions *JobCallOptions
236
237 // LROClient is used internally to handle long-running operations.
238 // It is exposed so that its CallOptions can be modified if required.
239 // Users should not Close this client.
240 LROClient *lroauto.OperationsClient
241 }
242
243 // Wrapper methods routed to the internal client.
244
245 // Close closes the connection to the API service. The user should invoke this when
246 // the client is no longer required.
247 func (c *JobClient) Close() error {
248 return c.internalClient.Close()
249 }
250
251 // setGoogleClientInfo sets the name and version of the application in
252 // the `x-goog-api-client` header passed on each request. Intended for
253 // use by Google-written clients.
254 func (c *JobClient) setGoogleClientInfo(keyval ...string) {
255 c.internalClient.setGoogleClientInfo(keyval...)
256 }
257
258 // Connection returns a connection to the API service.
259 //
260 // Deprecated: Connections are now pooled so this method does not always
261 // return the same resource.
262 func (c *JobClient) Connection() *grpc.ClientConn {
263 return c.internalClient.Connection()
264 }
265
266 // CreateJob creates a new job.
267 //
268 // Typically, the job becomes searchable within 10 seconds, but it may take
269 // up to 5 minutes.
270 func (c *JobClient) CreateJob(ctx context.Context, req *talentpb.CreateJobRequest, opts ...gax.CallOption) (*talentpb.Job, error) {
271 return c.internalClient.CreateJob(ctx, req, opts...)
272 }
273
274 // BatchCreateJobs begins executing a batch create jobs operation.
275 func (c *JobClient) BatchCreateJobs(ctx context.Context, req *talentpb.BatchCreateJobsRequest, opts ...gax.CallOption) (*BatchCreateJobsOperation, error) {
276 return c.internalClient.BatchCreateJobs(ctx, req, opts...)
277 }
278
279 // BatchCreateJobsOperation returns a new BatchCreateJobsOperation from a given name.
280 // The name must be that of a previously created BatchCreateJobsOperation, possibly from a different process.
281 func (c *JobClient) BatchCreateJobsOperation(name string) *BatchCreateJobsOperation {
282 return c.internalClient.BatchCreateJobsOperation(name)
283 }
284
285 // GetJob retrieves the specified job, whose status is OPEN or recently EXPIRED
286 // within the last 90 days.
287 func (c *JobClient) GetJob(ctx context.Context, req *talentpb.GetJobRequest, opts ...gax.CallOption) (*talentpb.Job, error) {
288 return c.internalClient.GetJob(ctx, req, opts...)
289 }
290
291 // UpdateJob updates specified job.
292 //
293 // Typically, updated contents become visible in search results within 10
294 // seconds, but it may take up to 5 minutes.
295 func (c *JobClient) UpdateJob(ctx context.Context, req *talentpb.UpdateJobRequest, opts ...gax.CallOption) (*talentpb.Job, error) {
296 return c.internalClient.UpdateJob(ctx, req, opts...)
297 }
298
299 // BatchUpdateJobs begins executing a batch update jobs operation.
300 func (c *JobClient) BatchUpdateJobs(ctx context.Context, req *talentpb.BatchUpdateJobsRequest, opts ...gax.CallOption) (*BatchUpdateJobsOperation, error) {
301 return c.internalClient.BatchUpdateJobs(ctx, req, opts...)
302 }
303
304 // BatchUpdateJobsOperation returns a new BatchUpdateJobsOperation from a given name.
305 // The name must be that of a previously created BatchUpdateJobsOperation, possibly from a different process.
306 func (c *JobClient) BatchUpdateJobsOperation(name string) *BatchUpdateJobsOperation {
307 return c.internalClient.BatchUpdateJobsOperation(name)
308 }
309
310 // DeleteJob deletes the specified job.
311 //
312 // Typically, the job becomes unsearchable within 10 seconds, but it may take
313 // up to 5 minutes.
314 func (c *JobClient) DeleteJob(ctx context.Context, req *talentpb.DeleteJobRequest, opts ...gax.CallOption) error {
315 return c.internalClient.DeleteJob(ctx, req, opts...)
316 }
317
318 // BatchDeleteJobs deletes a list of Jobs by filter.
319 func (c *JobClient) BatchDeleteJobs(ctx context.Context, req *talentpb.BatchDeleteJobsRequest, opts ...gax.CallOption) error {
320 return c.internalClient.BatchDeleteJobs(ctx, req, opts...)
321 }
322
323 // ListJobs lists jobs by filter.
324 func (c *JobClient) ListJobs(ctx context.Context, req *talentpb.ListJobsRequest, opts ...gax.CallOption) *JobIterator {
325 return c.internalClient.ListJobs(ctx, req, opts...)
326 }
327
328 // SearchJobs searches for jobs using the provided
329 // SearchJobsRequest.
330 //
331 // This call constrains the
332 // visibility of jobs present in
333 // the database, and only returns jobs that the caller has permission to
334 // search against.
335 func (c *JobClient) SearchJobs(ctx context.Context, req *talentpb.SearchJobsRequest, opts ...gax.CallOption) (*talentpb.SearchJobsResponse, error) {
336 return c.internalClient.SearchJobs(ctx, req, opts...)
337 }
338
339 // SearchJobsForAlert searches for jobs using the provided
340 // SearchJobsRequest.
341 //
342 // This API call is intended for the use case of targeting passive job
343 // seekers (for example, job seekers who have signed up to receive email
344 // alerts about potential job opportunities), and has different algorithmic
345 // adjustments that are targeted to passive job seekers.
346 //
347 // This call constrains the
348 // visibility of jobs present in
349 // the database, and only returns jobs the caller has permission to search
350 // against.
351 func (c *JobClient) SearchJobsForAlert(ctx context.Context, req *talentpb.SearchJobsRequest, opts ...gax.CallOption) *SearchJobsResponse_MatchingJobIterator {
352 return c.internalClient.SearchJobsForAlert(ctx, req, opts...)
353 }
354
355 // GetOperation is a utility method from google.longrunning.Operations.
356 func (c *JobClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
357 return c.internalClient.GetOperation(ctx, req, opts...)
358 }
359
360 // jobGRPCClient is a client for interacting with Cloud Talent Solution API over gRPC transport.
361 //
362 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
363 type jobGRPCClient struct {
364 // Connection pool of gRPC connections to the service.
365 connPool gtransport.ConnPool
366
367 // Points back to the CallOptions field of the containing JobClient
368 CallOptions **JobCallOptions
369
370 // The gRPC API client.
371 jobClient talentpb.JobServiceClient
372
373 // LROClient is used internally to handle long-running operations.
374 // It is exposed so that its CallOptions can be modified if required.
375 // Users should not Close this client.
376 LROClient **lroauto.OperationsClient
377
378 operationsClient longrunningpb.OperationsClient
379
380 // The x-goog-* metadata to be sent with each request.
381 xGoogHeaders []string
382
383 logger *slog.Logger
384 }
385
386 // NewJobClient creates a new job service client based on gRPC.
387 // The returned client must be Closed when it is done being used to clean up its underlying connections.
388 //
389 // A service handles job management, including job CRUD, enumeration and search.
390 func NewJobClient(ctx context.Context, opts ...option.ClientOption) (*JobClient, error) {
391 clientOpts := defaultJobGRPCClientOptions()
392 if newJobClientHook != nil {
393 hookOpts, err := newJobClientHook(ctx, clientHookParams{})
394 if err != nil {
395 return nil, err
396 }
397 clientOpts = append(clientOpts, hookOpts...)
398 }
399
400 connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
401 if err != nil {
402 return nil, err
403 }
404 client := JobClient{CallOptions: defaultJobCallOptions()}
405
406 c := &jobGRPCClient{
407 connPool: connPool,
408 jobClient: talentpb.NewJobServiceClient(connPool),
409 CallOptions: &client.CallOptions,
410 logger: internaloption.GetLogger(opts),
411 operationsClient: longrunningpb.NewOperationsClient(connPool),
412 }
413 c.setGoogleClientInfo()
414
415 client.internalClient = c
416
417 client.LROClient, err = lroauto.NewOperationsClient(ctx, gtransport.WithConnPool(connPool))
418 if err != nil {
419 // This error "should not happen", since we are just reusing old connection pool
420 // and never actually need to dial.
421 // If this does happen, we could leak connp. However, we cannot close conn:
422 // If the user invoked the constructor with option.WithGRPCConn,
423 // we would close a connection that's still in use.
424 // TODO: investigate error conditions.
425 return nil, err
426 }
427 c.LROClient = &client.LROClient
428 return &client, nil
429 }
430
431 // Connection returns a connection to the API service.
432 //
433 // Deprecated: Connections are now pooled so this method does not always
434 // return the same resource.
435 func (c *jobGRPCClient) Connection() *grpc.ClientConn {
436 return c.connPool.Conn()
437 }
438
439 // setGoogleClientInfo sets the name and version of the application in
440 // the `x-goog-api-client` header passed on each request. Intended for
441 // use by Google-written clients.
442 func (c *jobGRPCClient) setGoogleClientInfo(keyval ...string) {
443 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
444 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion)
445 c.xGoogHeaders = []string{
446 "x-goog-api-client", gax.XGoogHeader(kv...),
447 }
448 }
449
450 // Close closes the connection to the API service. The user should invoke this when
451 // the client is no longer required.
452 func (c *jobGRPCClient) Close() error {
453 return c.connPool.Close()
454 }
455
456 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
457 type jobRESTClient struct {
458 // The http endpoint to connect to.
459 endpoint string
460
461 // The http client.
462 httpClient *http.Client
463
464 // LROClient is used internally to handle long-running operations.
465 // It is exposed so that its CallOptions can be modified if required.
466 // Users should not Close this client.
467 LROClient **lroauto.OperationsClient
468
469 // The x-goog-* headers to be sent with each request.
470 xGoogHeaders []string
471
472 // Points back to the CallOptions field of the containing JobClient
473 CallOptions **JobCallOptions
474
475 logger *slog.Logger
476 }
477
478 // NewJobRESTClient creates a new job service rest client.
479 //
480 // A service handles job management, including job CRUD, enumeration and search.
481 func NewJobRESTClient(ctx context.Context, opts ...option.ClientOption) (*JobClient, error) {
482 clientOpts := append(defaultJobRESTClientOptions(), opts...)
483 httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...)
484 if err != nil {
485 return nil, err
486 }
487
488 callOpts := defaultJobRESTCallOptions()
489 c := &jobRESTClient{
490 endpoint: endpoint,
491 httpClient: httpClient,
492 CallOptions: &callOpts,
493 logger: internaloption.GetLogger(opts),
494 }
495 c.setGoogleClientInfo()
496
497 lroOpts := []option.ClientOption{
498 option.WithHTTPClient(httpClient),
499 option.WithEndpoint(endpoint),
500 }
501 opClient, err := lroauto.NewOperationsRESTClient(ctx, lroOpts...)
502 if err != nil {
503 return nil, err
504 }
505 c.LROClient = &opClient
506
507 return &JobClient{internalClient: c, CallOptions: callOpts}, nil
508 }
509
510 func defaultJobRESTClientOptions() []option.ClientOption {
511 return []option.ClientOption{
512 internaloption.WithDefaultEndpoint("https://jobs.googleapis.com"),
513 internaloption.WithDefaultEndpointTemplate("https://jobs.UNIVERSE_DOMAIN"),
514 internaloption.WithDefaultMTLSEndpoint("https://jobs.mtls.googleapis.com"),
515 internaloption.WithDefaultUniverseDomain("googleapis.com"),
516 internaloption.WithDefaultAudience("https://jobs.googleapis.com/"),
517 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
518 internaloption.EnableNewAuthLibrary(),
519 }
520 }
521
522 // setGoogleClientInfo sets the name and version of the application in
523 // the `x-goog-api-client` header passed on each request. Intended for
524 // use by Google-written clients.
525 func (c *jobRESTClient) setGoogleClientInfo(keyval ...string) {
526 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
527 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN", "pb", protoVersion)
528 c.xGoogHeaders = []string{
529 "x-goog-api-client", gax.XGoogHeader(kv...),
530 }
531 }
532
533 // Close closes the connection to the API service. The user should invoke this when
534 // the client is no longer required.
535 func (c *jobRESTClient) Close() error {
536 // Replace httpClient with nil to force cleanup.
537 c.httpClient = nil
538 return nil
539 }
540
541 // Connection returns a connection to the API service.
542 //
543 // Deprecated: This method always returns nil.
544 func (c *jobRESTClient) Connection() *grpc.ClientConn {
545 return nil
546 }
547 func (c *jobGRPCClient) CreateJob(ctx context.Context, req *talentpb.CreateJobRequest, opts ...gax.CallOption) (*talentpb.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 *talentpb.Job
554 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
555 var err error
556 resp, err = executeRPC(ctx, c.jobClient.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 *jobGRPCClient) BatchCreateJobs(ctx context.Context, req *talentpb.BatchCreateJobsRequest, opts ...gax.CallOption) (*BatchCreateJobsOperation, error) {
566 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
567
568 hds = append(c.xGoogHeaders, hds...)
569 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
570 opts = append((*c.CallOptions).BatchCreateJobs[0:len((*c.CallOptions).BatchCreateJobs):len((*c.CallOptions).BatchCreateJobs)], opts...)
571 var resp *longrunningpb.Operation
572 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
573 var err error
574 resp, err = executeRPC(ctx, c.jobClient.BatchCreateJobs, req, settings.GRPC, c.logger, "BatchCreateJobs")
575 return err
576 }, opts...)
577 if err != nil {
578 return nil, err
579 }
580 return &BatchCreateJobsOperation{
581 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
582 }, nil
583 }
584
585 func (c *jobGRPCClient) GetJob(ctx context.Context, req *talentpb.GetJobRequest, opts ...gax.CallOption) (*talentpb.Job, error) {
586 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
587
588 hds = append(c.xGoogHeaders, hds...)
589 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
590 opts = append((*c.CallOptions).GetJob[0:len((*c.CallOptions).GetJob):len((*c.CallOptions).GetJob)], opts...)
591 var resp *talentpb.Job
592 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
593 var err error
594 resp, err = executeRPC(ctx, c.jobClient.GetJob, req, settings.GRPC, c.logger, "GetJob")
595 return err
596 }, opts...)
597 if err != nil {
598 return nil, err
599 }
600 return resp, nil
601 }
602
603 func (c *jobGRPCClient) UpdateJob(ctx context.Context, req *talentpb.UpdateJobRequest, opts ...gax.CallOption) (*talentpb.Job, error) {
604 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "job.name", url.QueryEscape(req.GetJob().GetName()))}
605
606 hds = append(c.xGoogHeaders, hds...)
607 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
608 opts = append((*c.CallOptions).UpdateJob[0:len((*c.CallOptions).UpdateJob):len((*c.CallOptions).UpdateJob)], opts...)
609 var resp *talentpb.Job
610 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
611 var err error
612 resp, err = executeRPC(ctx, c.jobClient.UpdateJob, req, settings.GRPC, c.logger, "UpdateJob")
613 return err
614 }, opts...)
615 if err != nil {
616 return nil, err
617 }
618 return resp, nil
619 }
620
621 func (c *jobGRPCClient) BatchUpdateJobs(ctx context.Context, req *talentpb.BatchUpdateJobsRequest, opts ...gax.CallOption) (*BatchUpdateJobsOperation, error) {
622 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
623
624 hds = append(c.xGoogHeaders, hds...)
625 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
626 opts = append((*c.CallOptions).BatchUpdateJobs[0:len((*c.CallOptions).BatchUpdateJobs):len((*c.CallOptions).BatchUpdateJobs)], opts...)
627 var resp *longrunningpb.Operation
628 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
629 var err error
630 resp, err = executeRPC(ctx, c.jobClient.BatchUpdateJobs, req, settings.GRPC, c.logger, "BatchUpdateJobs")
631 return err
632 }, opts...)
633 if err != nil {
634 return nil, err
635 }
636 return &BatchUpdateJobsOperation{
637 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
638 }, nil
639 }
640
641 func (c *jobGRPCClient) DeleteJob(ctx context.Context, req *talentpb.DeleteJobRequest, opts ...gax.CallOption) error {
642 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
643
644 hds = append(c.xGoogHeaders, hds...)
645 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
646 opts = append((*c.CallOptions).DeleteJob[0:len((*c.CallOptions).DeleteJob):len((*c.CallOptions).DeleteJob)], opts...)
647 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
648 var err error
649 _, err = executeRPC(ctx, c.jobClient.DeleteJob, req, settings.GRPC, c.logger, "DeleteJob")
650 return err
651 }, opts...)
652 return err
653 }
654
655 func (c *jobGRPCClient) BatchDeleteJobs(ctx context.Context, req *talentpb.BatchDeleteJobsRequest, opts ...gax.CallOption) error {
656 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
657
658 hds = append(c.xGoogHeaders, hds...)
659 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
660 opts = append((*c.CallOptions).BatchDeleteJobs[0:len((*c.CallOptions).BatchDeleteJobs):len((*c.CallOptions).BatchDeleteJobs)], opts...)
661 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
662 var err error
663 _, err = executeRPC(ctx, c.jobClient.BatchDeleteJobs, req, settings.GRPC, c.logger, "BatchDeleteJobs")
664 return err
665 }, opts...)
666 return err
667 }
668
669 func (c *jobGRPCClient) ListJobs(ctx context.Context, req *talentpb.ListJobsRequest, opts ...gax.CallOption) *JobIterator {
670 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
671
672 hds = append(c.xGoogHeaders, hds...)
673 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
674 opts = append((*c.CallOptions).ListJobs[0:len((*c.CallOptions).ListJobs):len((*c.CallOptions).ListJobs)], opts...)
675 it := &JobIterator{}
676 req = proto.Clone(req).(*talentpb.ListJobsRequest)
677 it.InternalFetch = func(pageSize int, pageToken string) ([]*talentpb.Job, string, error) {
678 resp := &talentpb.ListJobsResponse{}
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.jobClient.ListJobs, req, settings.GRPC, c.logger, "ListJobs")
690 return err
691 }, opts...)
692 if err != nil {
693 return nil, "", err
694 }
695
696 it.Response = resp
697 return resp.GetJobs(), 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 func (c *jobGRPCClient) SearchJobs(ctx context.Context, req *talentpb.SearchJobsRequest, opts ...gax.CallOption) (*talentpb.SearchJobsResponse, error) {
716 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
717
718 hds = append(c.xGoogHeaders, hds...)
719 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
720 opts = append((*c.CallOptions).SearchJobs[0:len((*c.CallOptions).SearchJobs):len((*c.CallOptions).SearchJobs)], opts...)
721 var resp *talentpb.SearchJobsResponse
722 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
723 var err error
724 resp, err = executeRPC(ctx, c.jobClient.SearchJobs, req, settings.GRPC, c.logger, "SearchJobs")
725 return err
726 }, opts...)
727 if err != nil {
728 return nil, err
729 }
730 return resp, nil
731 }
732
733 func (c *jobGRPCClient) SearchJobsForAlert(ctx context.Context, req *talentpb.SearchJobsRequest, opts ...gax.CallOption) *SearchJobsResponse_MatchingJobIterator {
734 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
735
736 hds = append(c.xGoogHeaders, hds...)
737 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
738 opts = append((*c.CallOptions).SearchJobsForAlert[0:len((*c.CallOptions).SearchJobsForAlert):len((*c.CallOptions).SearchJobsForAlert)], opts...)
739 it := &SearchJobsResponse_MatchingJobIterator{}
740 req = proto.Clone(req).(*talentpb.SearchJobsRequest)
741 it.InternalFetch = func(pageSize int, pageToken string) ([]*talentpb.SearchJobsResponse_MatchingJob, string, error) {
742 resp := &talentpb.SearchJobsResponse{}
743 if pageToken != "" {
744 req.PageToken = pageToken
745 }
746 if pageSize > math.MaxInt32 {
747 req.PageSize = math.MaxInt32
748 } else if pageSize != 0 {
749 req.PageSize = int32(pageSize)
750 }
751 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
752 var err error
753 resp, err = executeRPC(ctx, c.jobClient.SearchJobsForAlert, req, settings.GRPC, c.logger, "SearchJobsForAlert")
754 return err
755 }, opts...)
756 if err != nil {
757 return nil, "", err
758 }
759
760 it.Response = resp
761 return resp.GetMatchingJobs(), resp.GetNextPageToken(), nil
762 }
763 fetch := func(pageSize int, pageToken string) (string, error) {
764 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
765 if err != nil {
766 return "", err
767 }
768 it.items = append(it.items, items...)
769 return nextPageToken, nil
770 }
771
772 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
773 it.pageInfo.MaxSize = int(req.GetPageSize())
774 it.pageInfo.Token = req.GetPageToken()
775
776 return it
777 }
778
779 func (c *jobGRPCClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
780 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
781
782 hds = append(c.xGoogHeaders, hds...)
783 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
784 opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...)
785 var resp *longrunningpb.Operation
786 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
787 var err error
788 resp, err = executeRPC(ctx, c.operationsClient.GetOperation, req, settings.GRPC, c.logger, "GetOperation")
789 return err
790 }, opts...)
791 if err != nil {
792 return nil, err
793 }
794 return resp, nil
795 }
796
797 // CreateJob creates a new job.
798 //
799 // Typically, the job becomes searchable within 10 seconds, but it may take
800 // up to 5 minutes.
801 func (c *jobRESTClient) CreateJob(ctx context.Context, req *talentpb.CreateJobRequest, opts ...gax.CallOption) (*talentpb.Job, error) {
802 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
803 jsonReq, err := m.Marshal(req)
804 if err != nil {
805 return nil, err
806 }
807
808 baseUrl, err := url.Parse(c.endpoint)
809 if err != nil {
810 return nil, err
811 }
812 baseUrl.Path += fmt.Sprintf("/v4beta1/%v/jobs", req.GetParent())
813
814 params := url.Values{}
815 params.Add("$alt", "json;enum-encoding=int")
816
817 baseUrl.RawQuery = params.Encode()
818
819 // Build HTTP headers from client and context metadata.
820 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
821
822 hds = append(c.xGoogHeaders, hds...)
823 hds = append(hds, "Content-Type", "application/json")
824 headers := gax.BuildHeaders(ctx, hds...)
825 opts = append((*c.CallOptions).CreateJob[0:len((*c.CallOptions).CreateJob):len((*c.CallOptions).CreateJob)], opts...)
826 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
827 resp := &talentpb.Job{}
828 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
829 if settings.Path != "" {
830 baseUrl.Path = settings.Path
831 }
832 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
833 if err != nil {
834 return err
835 }
836 httpReq = httpReq.WithContext(ctx)
837 httpReq.Header = headers
838
839 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CreateJob")
840 if err != nil {
841 return err
842 }
843
844 if err := unm.Unmarshal(buf, resp); err != nil {
845 return err
846 }
847
848 return nil
849 }, opts...)
850 if e != nil {
851 return nil, e
852 }
853 return resp, nil
854 }
855
856 // BatchCreateJobs begins executing a batch create jobs operation.
857 func (c *jobRESTClient) BatchCreateJobs(ctx context.Context, req *talentpb.BatchCreateJobsRequest, opts ...gax.CallOption) (*BatchCreateJobsOperation, error) {
858 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
859 jsonReq, err := m.Marshal(req)
860 if err != nil {
861 return nil, err
862 }
863
864 baseUrl, err := url.Parse(c.endpoint)
865 if err != nil {
866 return nil, err
867 }
868 baseUrl.Path += fmt.Sprintf("/v4beta1/%v/jobs:batchCreate", req.GetParent())
869
870 params := url.Values{}
871 params.Add("$alt", "json;enum-encoding=int")
872
873 baseUrl.RawQuery = params.Encode()
874
875 // Build HTTP headers from client and context metadata.
876 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
877
878 hds = append(c.xGoogHeaders, hds...)
879 hds = append(hds, "Content-Type", "application/json")
880 headers := gax.BuildHeaders(ctx, hds...)
881 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
882 resp := &longrunningpb.Operation{}
883 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
884 if settings.Path != "" {
885 baseUrl.Path = settings.Path
886 }
887 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
888 if err != nil {
889 return err
890 }
891 httpReq = httpReq.WithContext(ctx)
892 httpReq.Header = headers
893
894 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "BatchCreateJobs")
895 if err != nil {
896 return err
897 }
898 if err := unm.Unmarshal(buf, resp); err != nil {
899 return err
900 }
901
902 return nil
903 }, opts...)
904 if e != nil {
905 return nil, e
906 }
907
908 override := fmt.Sprintf("/v4beta1/%s", resp.GetName())
909 return &BatchCreateJobsOperation{
910 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
911 pollPath: override,
912 }, nil
913 }
914
915 // GetJob retrieves the specified job, whose status is OPEN or recently EXPIRED
916 // within the last 90 days.
917 func (c *jobRESTClient) GetJob(ctx context.Context, req *talentpb.GetJobRequest, opts ...gax.CallOption) (*talentpb.Job, error) {
918 baseUrl, err := url.Parse(c.endpoint)
919 if err != nil {
920 return nil, err
921 }
922 baseUrl.Path += fmt.Sprintf("/v4beta1/%v", req.GetName())
923
924 params := url.Values{}
925 params.Add("$alt", "json;enum-encoding=int")
926
927 baseUrl.RawQuery = params.Encode()
928
929 // Build HTTP headers from client and context metadata.
930 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
931
932 hds = append(c.xGoogHeaders, hds...)
933 hds = append(hds, "Content-Type", "application/json")
934 headers := gax.BuildHeaders(ctx, hds...)
935 opts = append((*c.CallOptions).GetJob[0:len((*c.CallOptions).GetJob):len((*c.CallOptions).GetJob)], opts...)
936 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
937 resp := &talentpb.Job{}
938 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
939 if settings.Path != "" {
940 baseUrl.Path = settings.Path
941 }
942 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
943 if err != nil {
944 return err
945 }
946 httpReq = httpReq.WithContext(ctx)
947 httpReq.Header = headers
948
949 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetJob")
950 if err != nil {
951 return err
952 }
953
954 if err := unm.Unmarshal(buf, resp); err != nil {
955 return err
956 }
957
958 return nil
959 }, opts...)
960 if e != nil {
961 return nil, e
962 }
963 return resp, nil
964 }
965
966 // UpdateJob updates specified job.
967 //
968 // Typically, updated contents become visible in search results within 10
969 // seconds, but it may take up to 5 minutes.
970 func (c *jobRESTClient) UpdateJob(ctx context.Context, req *talentpb.UpdateJobRequest, opts ...gax.CallOption) (*talentpb.Job, error) {
971 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
972 jsonReq, err := m.Marshal(req)
973 if err != nil {
974 return nil, err
975 }
976
977 baseUrl, err := url.Parse(c.endpoint)
978 if err != nil {
979 return nil, err
980 }
981 baseUrl.Path += fmt.Sprintf("/v4beta1/%v", req.GetJob().GetName())
982
983 params := url.Values{}
984 params.Add("$alt", "json;enum-encoding=int")
985
986 baseUrl.RawQuery = params.Encode()
987
988 // Build HTTP headers from client and context metadata.
989 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "job.name", url.QueryEscape(req.GetJob().GetName()))}
990
991 hds = append(c.xGoogHeaders, hds...)
992 hds = append(hds, "Content-Type", "application/json")
993 headers := gax.BuildHeaders(ctx, hds...)
994 opts = append((*c.CallOptions).UpdateJob[0:len((*c.CallOptions).UpdateJob):len((*c.CallOptions).UpdateJob)], opts...)
995 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
996 resp := &talentpb.Job{}
997 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
998 if settings.Path != "" {
999 baseUrl.Path = settings.Path
1000 }
1001 httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq))
1002 if err != nil {
1003 return err
1004 }
1005 httpReq = httpReq.WithContext(ctx)
1006 httpReq.Header = headers
1007
1008 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "UpdateJob")
1009 if err != nil {
1010 return err
1011 }
1012
1013 if err := unm.Unmarshal(buf, resp); err != nil {
1014 return err
1015 }
1016
1017 return nil
1018 }, opts...)
1019 if e != nil {
1020 return nil, e
1021 }
1022 return resp, nil
1023 }
1024
1025 // BatchUpdateJobs begins executing a batch update jobs operation.
1026 func (c *jobRESTClient) BatchUpdateJobs(ctx context.Context, req *talentpb.BatchUpdateJobsRequest, opts ...gax.CallOption) (*BatchUpdateJobsOperation, error) {
1027 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
1028 jsonReq, err := m.Marshal(req)
1029 if err != nil {
1030 return nil, err
1031 }
1032
1033 baseUrl, err := url.Parse(c.endpoint)
1034 if err != nil {
1035 return nil, err
1036 }
1037 baseUrl.Path += fmt.Sprintf("/v4beta1/%v/jobs:batchUpdate", req.GetParent())
1038
1039 params := url.Values{}
1040 params.Add("$alt", "json;enum-encoding=int")
1041
1042 baseUrl.RawQuery = params.Encode()
1043
1044 // Build HTTP headers from client and context metadata.
1045 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
1046
1047 hds = append(c.xGoogHeaders, hds...)
1048 hds = append(hds, "Content-Type", "application/json")
1049 headers := gax.BuildHeaders(ctx, hds...)
1050 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1051 resp := &longrunningpb.Operation{}
1052 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1053 if settings.Path != "" {
1054 baseUrl.Path = settings.Path
1055 }
1056 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
1057 if err != nil {
1058 return err
1059 }
1060 httpReq = httpReq.WithContext(ctx)
1061 httpReq.Header = headers
1062
1063 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "BatchUpdateJobs")
1064 if err != nil {
1065 return err
1066 }
1067 if err := unm.Unmarshal(buf, resp); err != nil {
1068 return err
1069 }
1070
1071 return nil
1072 }, opts...)
1073 if e != nil {
1074 return nil, e
1075 }
1076
1077 override := fmt.Sprintf("/v4beta1/%s", resp.GetName())
1078 return &BatchUpdateJobsOperation{
1079 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
1080 pollPath: override,
1081 }, nil
1082 }
1083
1084 // DeleteJob deletes the specified job.
1085 //
1086 // Typically, the job becomes unsearchable within 10 seconds, but it may take
1087 // up to 5 minutes.
1088 func (c *jobRESTClient) DeleteJob(ctx context.Context, req *talentpb.DeleteJobRequest, opts ...gax.CallOption) error {
1089 baseUrl, err := url.Parse(c.endpoint)
1090 if err != nil {
1091 return err
1092 }
1093 baseUrl.Path += fmt.Sprintf("/v4beta1/%v", 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 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1107 if settings.Path != "" {
1108 baseUrl.Path = settings.Path
1109 }
1110 httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil)
1111 if err != nil {
1112 return err
1113 }
1114 httpReq = httpReq.WithContext(ctx)
1115 httpReq.Header = headers
1116
1117 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteJob")
1118 return err
1119 }, opts...)
1120 }
1121
1122 // BatchDeleteJobs deletes a list of Jobs by filter.
1123 func (c *jobRESTClient) BatchDeleteJobs(ctx context.Context, req *talentpb.BatchDeleteJobsRequest, opts ...gax.CallOption) error {
1124 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
1125 jsonReq, err := m.Marshal(req)
1126 if err != nil {
1127 return err
1128 }
1129
1130 baseUrl, err := url.Parse(c.endpoint)
1131 if err != nil {
1132 return err
1133 }
1134 baseUrl.Path += fmt.Sprintf("/v4beta1/%v/jobs:batchDelete", req.GetParent())
1135
1136 params := url.Values{}
1137 params.Add("$alt", "json;enum-encoding=int")
1138
1139 baseUrl.RawQuery = params.Encode()
1140
1141 // Build HTTP headers from client and context metadata.
1142 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
1143
1144 hds = append(c.xGoogHeaders, hds...)
1145 hds = append(hds, "Content-Type", "application/json")
1146 headers := gax.BuildHeaders(ctx, hds...)
1147 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1148 if settings.Path != "" {
1149 baseUrl.Path = settings.Path
1150 }
1151 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
1152 if err != nil {
1153 return err
1154 }
1155 httpReq = httpReq.WithContext(ctx)
1156 httpReq.Header = headers
1157
1158 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "BatchDeleteJobs")
1159 return err
1160 }, opts...)
1161 }
1162
1163 // ListJobs lists jobs by filter.
1164 func (c *jobRESTClient) ListJobs(ctx context.Context, req *talentpb.ListJobsRequest, opts ...gax.CallOption) *JobIterator {
1165 it := &JobIterator{}
1166 req = proto.Clone(req).(*talentpb.ListJobsRequest)
1167 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1168 it.InternalFetch = func(pageSize int, pageToken string) ([]*talentpb.Job, string, error) {
1169 resp := &talentpb.ListJobsResponse{}
1170 if pageToken != "" {
1171 req.PageToken = pageToken
1172 }
1173 if pageSize > math.MaxInt32 {
1174 req.PageSize = math.MaxInt32
1175 } else if pageSize != 0 {
1176 req.PageSize = int32(pageSize)
1177 }
1178 baseUrl, err := url.Parse(c.endpoint)
1179 if err != nil {
1180 return nil, "", err
1181 }
1182 baseUrl.Path += fmt.Sprintf("/v4beta1/%v/jobs", req.GetParent())
1183
1184 params := url.Values{}
1185 params.Add("$alt", "json;enum-encoding=int")
1186 params.Add("filter", fmt.Sprintf("%v", req.GetFilter()))
1187 if req.GetJobView() != 0 {
1188 params.Add("jobView", fmt.Sprintf("%v", req.GetJobView()))
1189 }
1190 if req.GetPageSize() != 0 {
1191 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
1192 }
1193 if req.GetPageToken() != "" {
1194 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
1195 }
1196
1197 baseUrl.RawQuery = params.Encode()
1198
1199 // Build HTTP headers from client and context metadata.
1200 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
1201 headers := gax.BuildHeaders(ctx, hds...)
1202 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1203 if settings.Path != "" {
1204 baseUrl.Path = settings.Path
1205 }
1206 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
1207 if err != nil {
1208 return err
1209 }
1210 httpReq.Header = headers
1211
1212 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListJobs")
1213 if err != nil {
1214 return err
1215 }
1216 if err := unm.Unmarshal(buf, resp); err != nil {
1217 return err
1218 }
1219
1220 return nil
1221 }, opts...)
1222 if e != nil {
1223 return nil, "", e
1224 }
1225 it.Response = resp
1226 return resp.GetJobs(), resp.GetNextPageToken(), nil
1227 }
1228
1229 fetch := func(pageSize int, pageToken string) (string, error) {
1230 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
1231 if err != nil {
1232 return "", err
1233 }
1234 it.items = append(it.items, items...)
1235 return nextPageToken, nil
1236 }
1237
1238 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
1239 it.pageInfo.MaxSize = int(req.GetPageSize())
1240 it.pageInfo.Token = req.GetPageToken()
1241
1242 return it
1243 }
1244
1245 // SearchJobs searches for jobs using the provided
1246 // SearchJobsRequest.
1247 //
1248 // This call constrains the
1249 // visibility of jobs present in
1250 // the database, and only returns jobs that the caller has permission to
1251 // search against.
1252 func (c *jobRESTClient) SearchJobs(ctx context.Context, req *talentpb.SearchJobsRequest, opts ...gax.CallOption) (*talentpb.SearchJobsResponse, error) {
1253 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
1254 jsonReq, err := m.Marshal(req)
1255 if err != nil {
1256 return nil, err
1257 }
1258
1259 baseUrl, err := url.Parse(c.endpoint)
1260 if err != nil {
1261 return nil, err
1262 }
1263 baseUrl.Path += fmt.Sprintf("/v4beta1/%v/jobs:search", req.GetParent())
1264
1265 params := url.Values{}
1266 params.Add("$alt", "json;enum-encoding=int")
1267
1268 baseUrl.RawQuery = params.Encode()
1269
1270 // Build HTTP headers from client and context metadata.
1271 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
1272
1273 hds = append(c.xGoogHeaders, hds...)
1274 hds = append(hds, "Content-Type", "application/json")
1275 headers := gax.BuildHeaders(ctx, hds...)
1276 opts = append((*c.CallOptions).SearchJobs[0:len((*c.CallOptions).SearchJobs):len((*c.CallOptions).SearchJobs)], opts...)
1277 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1278 resp := &talentpb.SearchJobsResponse{}
1279 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1280 if settings.Path != "" {
1281 baseUrl.Path = settings.Path
1282 }
1283 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
1284 if err != nil {
1285 return err
1286 }
1287 httpReq = httpReq.WithContext(ctx)
1288 httpReq.Header = headers
1289
1290 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "SearchJobs")
1291 if err != nil {
1292 return err
1293 }
1294
1295 if err := unm.Unmarshal(buf, resp); err != nil {
1296 return err
1297 }
1298
1299 return nil
1300 }, opts...)
1301 if e != nil {
1302 return nil, e
1303 }
1304 return resp, nil
1305 }
1306
1307 // SearchJobsForAlert searches for jobs using the provided
1308 // SearchJobsRequest.
1309 //
1310 // This API call is intended for the use case of targeting passive job
1311 // seekers (for example, job seekers who have signed up to receive email
1312 // alerts about potential job opportunities), and has different algorithmic
1313 // adjustments that are targeted to passive job seekers.
1314 //
1315 // This call constrains the
1316 // visibility of jobs present in
1317 // the database, and only returns jobs the caller has permission to search
1318 // against.
1319 func (c *jobRESTClient) SearchJobsForAlert(ctx context.Context, req *talentpb.SearchJobsRequest, opts ...gax.CallOption) *SearchJobsResponse_MatchingJobIterator {
1320 it := &SearchJobsResponse_MatchingJobIterator{}
1321 req = proto.Clone(req).(*talentpb.SearchJobsRequest)
1322 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
1323 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1324 it.InternalFetch = func(pageSize int, pageToken string) ([]*talentpb.SearchJobsResponse_MatchingJob, string, error) {
1325 resp := &talentpb.SearchJobsResponse{}
1326 if pageToken != "" {
1327 req.PageToken = pageToken
1328 }
1329 if pageSize > math.MaxInt32 {
1330 req.PageSize = math.MaxInt32
1331 } else if pageSize != 0 {
1332 req.PageSize = int32(pageSize)
1333 }
1334 jsonReq, err := m.Marshal(req)
1335 if err != nil {
1336 return nil, "", err
1337 }
1338
1339 baseUrl, err := url.Parse(c.endpoint)
1340 if err != nil {
1341 return nil, "", err
1342 }
1343 baseUrl.Path += fmt.Sprintf("/v4beta1/%v/jobs:searchForAlert", req.GetParent())
1344
1345 params := url.Values{}
1346 params.Add("$alt", "json;enum-encoding=int")
1347
1348 baseUrl.RawQuery = params.Encode()
1349
1350 // Build HTTP headers from client and context metadata.
1351 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
1352 headers := gax.BuildHeaders(ctx, hds...)
1353 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1354 if settings.Path != "" {
1355 baseUrl.Path = settings.Path
1356 }
1357 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
1358 if err != nil {
1359 return err
1360 }
1361 httpReq.Header = headers
1362
1363 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "SearchJobsForAlert")
1364 if err != nil {
1365 return err
1366 }
1367 if err := unm.Unmarshal(buf, resp); err != nil {
1368 return err
1369 }
1370
1371 return nil
1372 }, opts...)
1373 if e != nil {
1374 return nil, "", e
1375 }
1376 it.Response = resp
1377 return resp.GetMatchingJobs(), resp.GetNextPageToken(), nil
1378 }
1379
1380 fetch := func(pageSize int, pageToken string) (string, error) {
1381 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
1382 if err != nil {
1383 return "", err
1384 }
1385 it.items = append(it.items, items...)
1386 return nextPageToken, nil
1387 }
1388
1389 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
1390 it.pageInfo.MaxSize = int(req.GetPageSize())
1391 it.pageInfo.Token = req.GetPageToken()
1392
1393 return it
1394 }
1395
1396 // GetOperation is a utility method from google.longrunning.Operations.
1397 func (c *jobRESTClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
1398 baseUrl, err := url.Parse(c.endpoint)
1399 if err != nil {
1400 return nil, err
1401 }
1402 baseUrl.Path += fmt.Sprintf("/v4beta1/%v", req.GetName())
1403
1404 params := url.Values{}
1405 params.Add("$alt", "json;enum-encoding=int")
1406
1407 baseUrl.RawQuery = params.Encode()
1408
1409 // Build HTTP headers from client and context metadata.
1410 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1411
1412 hds = append(c.xGoogHeaders, hds...)
1413 hds = append(hds, "Content-Type", "application/json")
1414 headers := gax.BuildHeaders(ctx, hds...)
1415 opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...)
1416 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1417 resp := &longrunningpb.Operation{}
1418 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1419 if settings.Path != "" {
1420 baseUrl.Path = settings.Path
1421 }
1422 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
1423 if err != nil {
1424 return err
1425 }
1426 httpReq = httpReq.WithContext(ctx)
1427 httpReq.Header = headers
1428
1429 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetOperation")
1430 if err != nil {
1431 return err
1432 }
1433
1434 if err := unm.Unmarshal(buf, resp); err != nil {
1435 return err
1436 }
1437
1438 return nil
1439 }, opts...)
1440 if e != nil {
1441 return nil, e
1442 }
1443 return resp, nil
1444 }
1445
1446 // BatchCreateJobsOperation returns a new BatchCreateJobsOperation from a given name.
1447 // The name must be that of a previously created BatchCreateJobsOperation, possibly from a different process.
1448 func (c *jobGRPCClient) BatchCreateJobsOperation(name string) *BatchCreateJobsOperation {
1449 return &BatchCreateJobsOperation{
1450 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
1451 }
1452 }
1453
1454 // BatchCreateJobsOperation returns a new BatchCreateJobsOperation from a given name.
1455 // The name must be that of a previously created BatchCreateJobsOperation, possibly from a different process.
1456 func (c *jobRESTClient) BatchCreateJobsOperation(name string) *BatchCreateJobsOperation {
1457 override := fmt.Sprintf("/v4beta1/%s", name)
1458 return &BatchCreateJobsOperation{
1459 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
1460 pollPath: override,
1461 }
1462 }
1463
1464 // BatchUpdateJobsOperation returns a new BatchUpdateJobsOperation from a given name.
1465 // The name must be that of a previously created BatchUpdateJobsOperation, possibly from a different process.
1466 func (c *jobGRPCClient) BatchUpdateJobsOperation(name string) *BatchUpdateJobsOperation {
1467 return &BatchUpdateJobsOperation{
1468 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
1469 }
1470 }
1471
1472 // BatchUpdateJobsOperation returns a new BatchUpdateJobsOperation from a given name.
1473 // The name must be that of a previously created BatchUpdateJobsOperation, possibly from a different process.
1474 func (c *jobRESTClient) BatchUpdateJobsOperation(name string) *BatchUpdateJobsOperation {
1475 override := fmt.Sprintf("/v4beta1/%s", name)
1476 return &BatchUpdateJobsOperation{
1477 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
1478 pollPath: override,
1479 }
1480 }