Debian Codegraph @

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