You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

429 lines
15 KiB

  1. // Copyright 2019 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. // Code generated by gapic-generator. DO NOT EDIT.
  15. package talent
  16. import (
  17. "context"
  18. "math"
  19. "time"
  20. "github.com/golang/protobuf/proto"
  21. gax "github.com/googleapis/gax-go/v2"
  22. "google.golang.org/api/iterator"
  23. "google.golang.org/api/option"
  24. "google.golang.org/api/transport"
  25. talentpb "google.golang.org/genproto/googleapis/cloud/talent/v4beta1"
  26. "google.golang.org/grpc"
  27. "google.golang.org/grpc/codes"
  28. "google.golang.org/grpc/metadata"
  29. )
  30. // JobCallOptions contains the retry settings for each method of JobClient.
  31. type JobCallOptions struct {
  32. CreateJob []gax.CallOption
  33. GetJob []gax.CallOption
  34. UpdateJob []gax.CallOption
  35. DeleteJob []gax.CallOption
  36. ListJobs []gax.CallOption
  37. BatchDeleteJobs []gax.CallOption
  38. SearchJobs []gax.CallOption
  39. SearchJobsForAlert []gax.CallOption
  40. }
  41. func defaultJobClientOptions() []option.ClientOption {
  42. return []option.ClientOption{
  43. option.WithEndpoint("jobs.googleapis.com:443"),
  44. option.WithScopes(DefaultAuthScopes()...),
  45. }
  46. }
  47. func defaultJobCallOptions() *JobCallOptions {
  48. retry := map[[2]string][]gax.CallOption{
  49. {"default", "idempotent"}: {
  50. gax.WithRetry(func() gax.Retryer {
  51. return gax.OnCodes([]codes.Code{
  52. codes.DeadlineExceeded,
  53. codes.Unavailable,
  54. }, gax.Backoff{
  55. Initial: 100 * time.Millisecond,
  56. Max: 60000 * time.Millisecond,
  57. Multiplier: 1.3,
  58. })
  59. }),
  60. },
  61. }
  62. return &JobCallOptions{
  63. CreateJob: retry[[2]string{"default", "non_idempotent"}],
  64. GetJob: retry[[2]string{"default", "idempotent"}],
  65. UpdateJob: retry[[2]string{"default", "non_idempotent"}],
  66. DeleteJob: retry[[2]string{"default", "idempotent"}],
  67. ListJobs: retry[[2]string{"default", "idempotent"}],
  68. BatchDeleteJobs: retry[[2]string{"default", "non_idempotent"}],
  69. SearchJobs: retry[[2]string{"default", "non_idempotent"}],
  70. SearchJobsForAlert: retry[[2]string{"default", "non_idempotent"}],
  71. }
  72. }
  73. // JobClient is a client for interacting with Cloud Talent Solution API.
  74. //
  75. // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
  76. type JobClient struct {
  77. // The connection to the service.
  78. conn *grpc.ClientConn
  79. // The gRPC API client.
  80. jobClient talentpb.JobServiceClient
  81. // The call options for this service.
  82. CallOptions *JobCallOptions
  83. // The x-goog-* metadata to be sent with each request.
  84. xGoogMetadata metadata.MD
  85. }
  86. // NewJobClient creates a new job service client.
  87. //
  88. // A service handles job management, including job CRUD, enumeration and search.
  89. func NewJobClient(ctx context.Context, opts ...option.ClientOption) (*JobClient, error) {
  90. conn, err := transport.DialGRPC(ctx, append(defaultJobClientOptions(), opts...)...)
  91. if err != nil {
  92. return nil, err
  93. }
  94. c := &JobClient{
  95. conn: conn,
  96. CallOptions: defaultJobCallOptions(),
  97. jobClient: talentpb.NewJobServiceClient(conn),
  98. }
  99. c.setGoogleClientInfo()
  100. return c, nil
  101. }
  102. // Connection returns the client's connection to the API service.
  103. func (c *JobClient) Connection() *grpc.ClientConn {
  104. return c.conn
  105. }
  106. // Close closes the connection to the API service. The user should invoke this when
  107. // the client is no longer required.
  108. func (c *JobClient) Close() error {
  109. return c.conn.Close()
  110. }
  111. // setGoogleClientInfo sets the name and version of the application in
  112. // the `x-goog-api-client` header passed on each request. Intended for
  113. // use by Google-written clients.
  114. func (c *JobClient) setGoogleClientInfo(keyval ...string) {
  115. kv := append([]string{"gl-go", versionGo()}, keyval...)
  116. kv = append(kv, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version)
  117. c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...))
  118. }
  119. // CreateJob creates a new job.
  120. //
  121. // Typically, the job becomes searchable within 10 seconds, but it may take
  122. // up to 5 minutes.
  123. func (c *JobClient) CreateJob(ctx context.Context, req *talentpb.CreateJobRequest, opts ...gax.CallOption) (*talentpb.Job, error) {
  124. ctx = insertMetadata(ctx, c.xGoogMetadata)
  125. opts = append(c.CallOptions.CreateJob[0:len(c.CallOptions.CreateJob):len(c.CallOptions.CreateJob)], opts...)
  126. var resp *talentpb.Job
  127. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  128. var err error
  129. resp, err = c.jobClient.CreateJob(ctx, req, settings.GRPC...)
  130. return err
  131. }, opts...)
  132. if err != nil {
  133. return nil, err
  134. }
  135. return resp, nil
  136. }
  137. // GetJob retrieves the specified job, whose status is OPEN or recently EXPIRED
  138. // within the last 90 days.
  139. func (c *JobClient) GetJob(ctx context.Context, req *talentpb.GetJobRequest, opts ...gax.CallOption) (*talentpb.Job, error) {
  140. ctx = insertMetadata(ctx, c.xGoogMetadata)
  141. opts = append(c.CallOptions.GetJob[0:len(c.CallOptions.GetJob):len(c.CallOptions.GetJob)], opts...)
  142. var resp *talentpb.Job
  143. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  144. var err error
  145. resp, err = c.jobClient.GetJob(ctx, req, settings.GRPC...)
  146. return err
  147. }, opts...)
  148. if err != nil {
  149. return nil, err
  150. }
  151. return resp, nil
  152. }
  153. // UpdateJob updates specified job.
  154. //
  155. // Typically, updated contents become visible in search results within 10
  156. // seconds, but it may take up to 5 minutes.
  157. func (c *JobClient) UpdateJob(ctx context.Context, req *talentpb.UpdateJobRequest, opts ...gax.CallOption) (*talentpb.Job, error) {
  158. ctx = insertMetadata(ctx, c.xGoogMetadata)
  159. opts = append(c.CallOptions.UpdateJob[0:len(c.CallOptions.UpdateJob):len(c.CallOptions.UpdateJob)], opts...)
  160. var resp *talentpb.Job
  161. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  162. var err error
  163. resp, err = c.jobClient.UpdateJob(ctx, req, settings.GRPC...)
  164. return err
  165. }, opts...)
  166. if err != nil {
  167. return nil, err
  168. }
  169. return resp, nil
  170. }
  171. // DeleteJob deletes the specified job.
  172. //
  173. // Typically, the job becomes unsearchable within 10 seconds, but it may take
  174. // up to 5 minutes.
  175. func (c *JobClient) DeleteJob(ctx context.Context, req *talentpb.DeleteJobRequest, opts ...gax.CallOption) error {
  176. ctx = insertMetadata(ctx, c.xGoogMetadata)
  177. opts = append(c.CallOptions.DeleteJob[0:len(c.CallOptions.DeleteJob):len(c.CallOptions.DeleteJob)], opts...)
  178. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  179. var err error
  180. _, err = c.jobClient.DeleteJob(ctx, req, settings.GRPC...)
  181. return err
  182. }, opts...)
  183. return err
  184. }
  185. // ListJobs lists jobs by filter.
  186. func (c *JobClient) ListJobs(ctx context.Context, req *talentpb.ListJobsRequest, opts ...gax.CallOption) *JobIterator {
  187. ctx = insertMetadata(ctx, c.xGoogMetadata)
  188. opts = append(c.CallOptions.ListJobs[0:len(c.CallOptions.ListJobs):len(c.CallOptions.ListJobs)], opts...)
  189. it := &JobIterator{}
  190. req = proto.Clone(req).(*talentpb.ListJobsRequest)
  191. it.InternalFetch = func(pageSize int, pageToken string) ([]*talentpb.Job, string, error) {
  192. var resp *talentpb.ListJobsResponse
  193. req.PageToken = pageToken
  194. if pageSize > math.MaxInt32 {
  195. req.PageSize = math.MaxInt32
  196. } else {
  197. req.PageSize = int32(pageSize)
  198. }
  199. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  200. var err error
  201. resp, err = c.jobClient.ListJobs(ctx, req, settings.GRPC...)
  202. return err
  203. }, opts...)
  204. if err != nil {
  205. return nil, "", err
  206. }
  207. return resp.Jobs, resp.NextPageToken, nil
  208. }
  209. fetch := func(pageSize int, pageToken string) (string, error) {
  210. items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
  211. if err != nil {
  212. return "", err
  213. }
  214. it.items = append(it.items, items...)
  215. return nextPageToken, nil
  216. }
  217. it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
  218. it.pageInfo.MaxSize = int(req.PageSize)
  219. return it
  220. }
  221. // BatchDeleteJobs deletes a list of [Job][google.cloud.talent.v4beta1.Job]s by filter.
  222. func (c *JobClient) BatchDeleteJobs(ctx context.Context, req *talentpb.BatchDeleteJobsRequest, opts ...gax.CallOption) error {
  223. ctx = insertMetadata(ctx, c.xGoogMetadata)
  224. opts = append(c.CallOptions.BatchDeleteJobs[0:len(c.CallOptions.BatchDeleteJobs):len(c.CallOptions.BatchDeleteJobs)], opts...)
  225. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  226. var err error
  227. _, err = c.jobClient.BatchDeleteJobs(ctx, req, settings.GRPC...)
  228. return err
  229. }, opts...)
  230. return err
  231. }
  232. // SearchJobs searches for jobs using the provided
  233. // [SearchJobsRequest][google.cloud.talent.v4beta1.SearchJobsRequest].
  234. //
  235. // This call constrains the
  236. // [visibility][google.cloud.talent.v4beta1.Job.visibility] of jobs present in
  237. // the database, and only returns jobs that the caller has permission to
  238. // search against.
  239. func (c *JobClient) SearchJobs(ctx context.Context, req *talentpb.SearchJobsRequest, opts ...gax.CallOption) *SearchJobsResponse_MatchingJobIterator {
  240. ctx = insertMetadata(ctx, c.xGoogMetadata)
  241. opts = append(c.CallOptions.SearchJobs[0:len(c.CallOptions.SearchJobs):len(c.CallOptions.SearchJobs)], opts...)
  242. it := &SearchJobsResponse_MatchingJobIterator{}
  243. req = proto.Clone(req).(*talentpb.SearchJobsRequest)
  244. it.InternalFetch = func(pageSize int, pageToken string) ([]*talentpb.SearchJobsResponse_MatchingJob, string, error) {
  245. var resp *talentpb.SearchJobsResponse
  246. req.PageToken = pageToken
  247. if pageSize > math.MaxInt32 {
  248. req.PageSize = math.MaxInt32
  249. } else {
  250. req.PageSize = int32(pageSize)
  251. }
  252. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  253. var err error
  254. resp, err = c.jobClient.SearchJobs(ctx, req, settings.GRPC...)
  255. return err
  256. }, opts...)
  257. if err != nil {
  258. return nil, "", err
  259. }
  260. return resp.MatchingJobs, resp.NextPageToken, nil
  261. }
  262. fetch := func(pageSize int, pageToken string) (string, error) {
  263. items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
  264. if err != nil {
  265. return "", err
  266. }
  267. it.items = append(it.items, items...)
  268. return nextPageToken, nil
  269. }
  270. it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
  271. it.pageInfo.MaxSize = int(req.PageSize)
  272. return it
  273. }
  274. // SearchJobsForAlert searches for jobs using the provided
  275. // [SearchJobsRequest][google.cloud.talent.v4beta1.SearchJobsRequest].
  276. //
  277. // This API call is intended for the use case of targeting passive job
  278. // seekers (for example, job seekers who have signed up to receive email
  279. // alerts about potential job opportunities), and has different algorithmic
  280. // adjustments that are targeted to passive job seekers.
  281. //
  282. // This call constrains the
  283. // [visibility][google.cloud.talent.v4beta1.Job.visibility] of jobs present in
  284. // the database, and only returns jobs the caller has permission to search
  285. // against.
  286. func (c *JobClient) SearchJobsForAlert(ctx context.Context, req *talentpb.SearchJobsRequest, opts ...gax.CallOption) *SearchJobsResponse_MatchingJobIterator {
  287. ctx = insertMetadata(ctx, c.xGoogMetadata)
  288. opts = append(c.CallOptions.SearchJobsForAlert[0:len(c.CallOptions.SearchJobsForAlert):len(c.CallOptions.SearchJobsForAlert)], opts...)
  289. it := &SearchJobsResponse_MatchingJobIterator{}
  290. req = proto.Clone(req).(*talentpb.SearchJobsRequest)
  291. it.InternalFetch = func(pageSize int, pageToken string) ([]*talentpb.SearchJobsResponse_MatchingJob, string, error) {
  292. var resp *talentpb.SearchJobsResponse
  293. req.PageToken = pageToken
  294. if pageSize > math.MaxInt32 {
  295. req.PageSize = math.MaxInt32
  296. } else {
  297. req.PageSize = int32(pageSize)
  298. }
  299. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  300. var err error
  301. resp, err = c.jobClient.SearchJobsForAlert(ctx, req, settings.GRPC...)
  302. return err
  303. }, opts...)
  304. if err != nil {
  305. return nil, "", err
  306. }
  307. return resp.MatchingJobs, resp.NextPageToken, nil
  308. }
  309. fetch := func(pageSize int, pageToken string) (string, error) {
  310. items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
  311. if err != nil {
  312. return "", err
  313. }
  314. it.items = append(it.items, items...)
  315. return nextPageToken, nil
  316. }
  317. it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
  318. it.pageInfo.MaxSize = int(req.PageSize)
  319. return it
  320. }
  321. // JobIterator manages a stream of *talentpb.Job.
  322. type JobIterator struct {
  323. items []*talentpb.Job
  324. pageInfo *iterator.PageInfo
  325. nextFunc func() error
  326. // InternalFetch is for use by the Google Cloud Libraries only.
  327. // It is not part of the stable interface of this package.
  328. //
  329. // InternalFetch returns results from a single call to the underlying RPC.
  330. // The number of results is no greater than pageSize.
  331. // If there are no more results, nextPageToken is empty and err is nil.
  332. InternalFetch func(pageSize int, pageToken string) (results []*talentpb.Job, nextPageToken string, err error)
  333. }
  334. // PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
  335. func (it *JobIterator) PageInfo() *iterator.PageInfo {
  336. return it.pageInfo
  337. }
  338. // Next returns the next result. Its second return value is iterator.Done if there are no more
  339. // results. Once Next returns Done, all subsequent calls will return Done.
  340. func (it *JobIterator) Next() (*talentpb.Job, error) {
  341. var item *talentpb.Job
  342. if err := it.nextFunc(); err != nil {
  343. return item, err
  344. }
  345. item = it.items[0]
  346. it.items = it.items[1:]
  347. return item, nil
  348. }
  349. func (it *JobIterator) bufLen() int {
  350. return len(it.items)
  351. }
  352. func (it *JobIterator) takeBuf() interface{} {
  353. b := it.items
  354. it.items = nil
  355. return b
  356. }
  357. // SearchJobsResponse_MatchingJobIterator manages a stream of *talentpb.SearchJobsResponse_MatchingJob.
  358. type SearchJobsResponse_MatchingJobIterator struct {
  359. items []*talentpb.SearchJobsResponse_MatchingJob
  360. pageInfo *iterator.PageInfo
  361. nextFunc func() error
  362. // InternalFetch is for use by the Google Cloud Libraries only.
  363. // It is not part of the stable interface of this package.
  364. //
  365. // InternalFetch returns results from a single call to the underlying RPC.
  366. // The number of results is no greater than pageSize.
  367. // If there are no more results, nextPageToken is empty and err is nil.
  368. InternalFetch func(pageSize int, pageToken string) (results []*talentpb.SearchJobsResponse_MatchingJob, nextPageToken string, err error)
  369. }
  370. // PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
  371. func (it *SearchJobsResponse_MatchingJobIterator) PageInfo() *iterator.PageInfo {
  372. return it.pageInfo
  373. }
  374. // Next returns the next result. Its second return value is iterator.Done if there are no more
  375. // results. Once Next returns Done, all subsequent calls will return Done.
  376. func (it *SearchJobsResponse_MatchingJobIterator) Next() (*talentpb.SearchJobsResponse_MatchingJob, error) {
  377. var item *talentpb.SearchJobsResponse_MatchingJob
  378. if err := it.nextFunc(); err != nil {
  379. return item, err
  380. }
  381. item = it.items[0]
  382. it.items = it.items[1:]
  383. return item, nil
  384. }
  385. func (it *SearchJobsResponse_MatchingJobIterator) bufLen() int {
  386. return len(it.items)
  387. }
  388. func (it *SearchJobsResponse_MatchingJobIterator) takeBuf() interface{} {
  389. b := it.items
  390. it.items = nil
  391. return b
  392. }