google-cloud-scheduler-v1 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,966 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2020 Google LLC
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # https://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ # Auto-generated by gapic-generator-ruby. DO NOT EDIT!
18
+
19
+ require "google/cloud/errors"
20
+ require "google/cloud/scheduler/v1/cloudscheduler_pb"
21
+
22
+ module Google
23
+ module Cloud
24
+ module Scheduler
25
+ module V1
26
+ module CloudScheduler
27
+ ##
28
+ # Client for the CloudScheduler service.
29
+ #
30
+ # The Cloud Scheduler API allows external entities to reliably
31
+ # schedule asynchronous jobs.
32
+ #
33
+ class Client
34
+ include Paths
35
+
36
+ # @private
37
+ attr_reader :cloud_scheduler_stub
38
+
39
+ ##
40
+ # Configure the CloudScheduler Client class.
41
+ #
42
+ # See {::Google::Cloud::Scheduler::V1::CloudScheduler::Client::Configuration}
43
+ # for a description of the configuration fields.
44
+ #
45
+ # ## Example
46
+ #
47
+ # To modify the configuration for all CloudScheduler clients:
48
+ #
49
+ # ::Google::Cloud::Scheduler::V1::CloudScheduler::Client.configure do |config|
50
+ # config.timeout = 10.0
51
+ # end
52
+ #
53
+ # @yield [config] Configure the Client client.
54
+ # @yieldparam config [Client::Configuration]
55
+ #
56
+ # @return [Client::Configuration]
57
+ #
58
+ def self.configure
59
+ @configure ||= begin
60
+ namespace = ["Google", "Cloud", "Scheduler", "V1"]
61
+ parent_config = while namespace.any?
62
+ parent_name = namespace.join "::"
63
+ parent_const = const_get parent_name
64
+ break parent_const.configure if parent_const&.respond_to? :configure
65
+ namespace.pop
66
+ end
67
+ default_config = Client::Configuration.new parent_config
68
+
69
+ default_config.rpcs.list_jobs.timeout = 600.0
70
+ default_config.rpcs.list_jobs.retry_policy = {
71
+ initial_delay: 0.1,
72
+ max_delay: 60.0,
73
+ multiplier: 1.3,
74
+ retry_codes: ["DEADLINE_EXCEEDED", "UNAVAILABLE"]
75
+ }
76
+
77
+ default_config.rpcs.get_job.timeout = 600.0
78
+ default_config.rpcs.get_job.retry_policy = {
79
+ initial_delay: 0.1,
80
+ max_delay: 60.0,
81
+ multiplier: 1.3,
82
+ retry_codes: ["DEADLINE_EXCEEDED", "UNAVAILABLE"]
83
+ }
84
+
85
+ default_config.rpcs.create_job.timeout = 600.0
86
+
87
+ default_config.rpcs.update_job.timeout = 600.0
88
+
89
+ default_config.rpcs.delete_job.timeout = 600.0
90
+ default_config.rpcs.delete_job.retry_policy = {
91
+ initial_delay: 0.1,
92
+ max_delay: 60.0,
93
+ multiplier: 1.3,
94
+ retry_codes: ["DEADLINE_EXCEEDED", "UNAVAILABLE"]
95
+ }
96
+
97
+ default_config.rpcs.pause_job.timeout = 600.0
98
+
99
+ default_config.rpcs.resume_job.timeout = 600.0
100
+
101
+ default_config.rpcs.run_job.timeout = 600.0
102
+
103
+ default_config
104
+ end
105
+ yield @configure if block_given?
106
+ @configure
107
+ end
108
+
109
+ ##
110
+ # Configure the CloudScheduler Client instance.
111
+ #
112
+ # The configuration is set to the derived mode, meaning that values can be changed,
113
+ # but structural changes (adding new fields, etc.) are not allowed. Structural changes
114
+ # should be made on {Client.configure}.
115
+ #
116
+ # See {::Google::Cloud::Scheduler::V1::CloudScheduler::Client::Configuration}
117
+ # for a description of the configuration fields.
118
+ #
119
+ # @yield [config] Configure the Client client.
120
+ # @yieldparam config [Client::Configuration]
121
+ #
122
+ # @return [Client::Configuration]
123
+ #
124
+ def configure
125
+ yield @config if block_given?
126
+ @config
127
+ end
128
+
129
+ ##
130
+ # Create a new CloudScheduler client object.
131
+ #
132
+ # ## Examples
133
+ #
134
+ # To create a new CloudScheduler client with the default
135
+ # configuration:
136
+ #
137
+ # client = ::Google::Cloud::Scheduler::V1::CloudScheduler::Client.new
138
+ #
139
+ # To create a new CloudScheduler client with a custom
140
+ # configuration:
141
+ #
142
+ # client = ::Google::Cloud::Scheduler::V1::CloudScheduler::Client.new do |config|
143
+ # config.timeout = 10.0
144
+ # end
145
+ #
146
+ # @yield [config] Configure the CloudScheduler client.
147
+ # @yieldparam config [Client::Configuration]
148
+ #
149
+ def initialize
150
+ # These require statements are intentionally placed here to initialize
151
+ # the gRPC module only when it's required.
152
+ # See https://github.com/googleapis/toolkit/issues/446
153
+ require "gapic/grpc"
154
+ require "google/cloud/scheduler/v1/cloudscheduler_services_pb"
155
+
156
+ # Create the configuration object
157
+ @config = Configuration.new Client.configure
158
+
159
+ # Yield the configuration if needed
160
+ yield @config if block_given?
161
+
162
+ # Create credentials
163
+ credentials = @config.credentials
164
+ credentials ||= Credentials.default scope: @config.scope
165
+ if credentials.is_a?(String) || credentials.is_a?(Hash)
166
+ credentials = Credentials.new credentials, scope: @config.scope
167
+ end
168
+ @quota_project_id = credentials.respond_to?(:quota_project_id) ? credentials.quota_project_id : nil
169
+
170
+ @cloud_scheduler_stub = ::Gapic::ServiceStub.new(
171
+ ::Google::Cloud::Scheduler::V1::CloudScheduler::Stub,
172
+ credentials: credentials,
173
+ endpoint: @config.endpoint,
174
+ channel_args: @config.channel_args,
175
+ interceptors: @config.interceptors
176
+ )
177
+ end
178
+
179
+ # Service calls
180
+
181
+ ##
182
+ # Lists jobs.
183
+ #
184
+ # @overload list_jobs(request, options = nil)
185
+ # Pass arguments to `list_jobs` via a request object, either of type
186
+ # {::Google::Cloud::Scheduler::V1::ListJobsRequest} or an equivalent Hash.
187
+ #
188
+ # @param request [::Google::Cloud::Scheduler::V1::ListJobsRequest, ::Hash]
189
+ # A request object representing the call parameters. Required. To specify no
190
+ # parameters, or to keep all the default parameter values, pass an empty Hash.
191
+ # @param options [::Gapic::CallOptions, ::Hash]
192
+ # Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
193
+ #
194
+ # @overload list_jobs(parent: nil, page_size: nil, page_token: nil)
195
+ # Pass arguments to `list_jobs` via keyword arguments. Note that at
196
+ # least one keyword argument is required. To specify no parameters, or to keep all
197
+ # the default parameter values, pass an empty Hash as a request object (see above).
198
+ #
199
+ # @param parent [::String]
200
+ # Required. The location name. For example:
201
+ # `projects/PROJECT_ID/locations/LOCATION_ID`.
202
+ # @param page_size [::Integer]
203
+ # Requested page size.
204
+ #
205
+ # The maximum page size is 500. If unspecified, the page size will
206
+ # be the maximum. Fewer jobs than requested might be returned,
207
+ # even if more jobs exist; use next_page_token to determine if more
208
+ # jobs exist.
209
+ # @param page_token [::String]
210
+ # A token identifying a page of results the server will return. To
211
+ # request the first page results, page_token must be empty. To
212
+ # request the next page of results, page_token must be the value of
213
+ # {::Google::Cloud::Scheduler::V1::ListJobsResponse#next_page_token next_page_token} returned from
214
+ # the previous call to {::Google::Cloud::Scheduler::V1::CloudScheduler::Client#list_jobs ListJobs}. It is an error to
215
+ # switch the value of [filter][google.cloud.scheduler.v1.ListJobsRequest.filter] or
216
+ # [order_by][google.cloud.scheduler.v1.ListJobsRequest.order_by] while iterating through pages.
217
+ #
218
+ # @yield [response, operation] Access the result along with the RPC operation
219
+ # @yieldparam response [::Gapic::PagedEnumerable<::Google::Cloud::Scheduler::V1::Job>]
220
+ # @yieldparam operation [::GRPC::ActiveCall::Operation]
221
+ #
222
+ # @return [::Gapic::PagedEnumerable<::Google::Cloud::Scheduler::V1::Job>]
223
+ #
224
+ # @raise [::Google::Cloud::Error] if the RPC is aborted.
225
+ #
226
+ def list_jobs request, options = nil
227
+ raise ::ArgumentError, "request must be provided" if request.nil?
228
+
229
+ request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Scheduler::V1::ListJobsRequest
230
+
231
+ # Converts hash and nil to an options object
232
+ options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
233
+
234
+ # Customize the options with defaults
235
+ metadata = @config.rpcs.list_jobs.metadata.to_h
236
+
237
+ # Set x-goog-api-client and x-goog-user-project headers
238
+ metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
239
+ lib_name: @config.lib_name, lib_version: @config.lib_version,
240
+ gapic_version: ::Google::Cloud::Scheduler::V1::VERSION
241
+ metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
242
+
243
+ header_params = {
244
+ "parent" => request.parent
245
+ }
246
+ request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
247
+ metadata[:"x-goog-request-params"] ||= request_params_header
248
+
249
+ options.apply_defaults timeout: @config.rpcs.list_jobs.timeout,
250
+ metadata: metadata,
251
+ retry_policy: @config.rpcs.list_jobs.retry_policy
252
+ options.apply_defaults metadata: @config.metadata,
253
+ retry_policy: @config.retry_policy
254
+
255
+ @cloud_scheduler_stub.call_rpc :list_jobs, request, options: options do |response, operation|
256
+ response = ::Gapic::PagedEnumerable.new @cloud_scheduler_stub, :list_jobs, request, response, operation, options
257
+ yield response, operation if block_given?
258
+ return response
259
+ end
260
+ rescue ::GRPC::BadStatus => e
261
+ raise ::Google::Cloud::Error.from_error(e)
262
+ end
263
+
264
+ ##
265
+ # Gets a job.
266
+ #
267
+ # @overload get_job(request, options = nil)
268
+ # Pass arguments to `get_job` via a request object, either of type
269
+ # {::Google::Cloud::Scheduler::V1::GetJobRequest} or an equivalent Hash.
270
+ #
271
+ # @param request [::Google::Cloud::Scheduler::V1::GetJobRequest, ::Hash]
272
+ # A request object representing the call parameters. Required. To specify no
273
+ # parameters, or to keep all the default parameter values, pass an empty Hash.
274
+ # @param options [::Gapic::CallOptions, ::Hash]
275
+ # Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
276
+ #
277
+ # @overload get_job(name: nil)
278
+ # Pass arguments to `get_job` via keyword arguments. Note that at
279
+ # least one keyword argument is required. To specify no parameters, or to keep all
280
+ # the default parameter values, pass an empty Hash as a request object (see above).
281
+ #
282
+ # @param name [::String]
283
+ # Required. The job name. For example:
284
+ # `projects/PROJECT_ID/locations/LOCATION_ID/jobs/JOB_ID`.
285
+ #
286
+ # @yield [response, operation] Access the result along with the RPC operation
287
+ # @yieldparam response [::Google::Cloud::Scheduler::V1::Job]
288
+ # @yieldparam operation [::GRPC::ActiveCall::Operation]
289
+ #
290
+ # @return [::Google::Cloud::Scheduler::V1::Job]
291
+ #
292
+ # @raise [::Google::Cloud::Error] if the RPC is aborted.
293
+ #
294
+ def get_job request, options = nil
295
+ raise ::ArgumentError, "request must be provided" if request.nil?
296
+
297
+ request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Scheduler::V1::GetJobRequest
298
+
299
+ # Converts hash and nil to an options object
300
+ options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
301
+
302
+ # Customize the options with defaults
303
+ metadata = @config.rpcs.get_job.metadata.to_h
304
+
305
+ # Set x-goog-api-client and x-goog-user-project headers
306
+ metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
307
+ lib_name: @config.lib_name, lib_version: @config.lib_version,
308
+ gapic_version: ::Google::Cloud::Scheduler::V1::VERSION
309
+ metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
310
+
311
+ header_params = {
312
+ "name" => request.name
313
+ }
314
+ request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
315
+ metadata[:"x-goog-request-params"] ||= request_params_header
316
+
317
+ options.apply_defaults timeout: @config.rpcs.get_job.timeout,
318
+ metadata: metadata,
319
+ retry_policy: @config.rpcs.get_job.retry_policy
320
+ options.apply_defaults metadata: @config.metadata,
321
+ retry_policy: @config.retry_policy
322
+
323
+ @cloud_scheduler_stub.call_rpc :get_job, request, options: options do |response, operation|
324
+ yield response, operation if block_given?
325
+ return response
326
+ end
327
+ rescue ::GRPC::BadStatus => e
328
+ raise ::Google::Cloud::Error.from_error(e)
329
+ end
330
+
331
+ ##
332
+ # Creates a job.
333
+ #
334
+ # @overload create_job(request, options = nil)
335
+ # Pass arguments to `create_job` via a request object, either of type
336
+ # {::Google::Cloud::Scheduler::V1::CreateJobRequest} or an equivalent Hash.
337
+ #
338
+ # @param request [::Google::Cloud::Scheduler::V1::CreateJobRequest, ::Hash]
339
+ # A request object representing the call parameters. Required. To specify no
340
+ # parameters, or to keep all the default parameter values, pass an empty Hash.
341
+ # @param options [::Gapic::CallOptions, ::Hash]
342
+ # Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
343
+ #
344
+ # @overload create_job(parent: nil, job: nil)
345
+ # Pass arguments to `create_job` via keyword arguments. Note that at
346
+ # least one keyword argument is required. To specify no parameters, or to keep all
347
+ # the default parameter values, pass an empty Hash as a request object (see above).
348
+ #
349
+ # @param parent [::String]
350
+ # Required. The location name. For example:
351
+ # `projects/PROJECT_ID/locations/LOCATION_ID`.
352
+ # @param job [::Google::Cloud::Scheduler::V1::Job, ::Hash]
353
+ # Required. The job to add. The user can optionally specify a name for the
354
+ # job in {::Google::Cloud::Scheduler::V1::Job#name name}. {::Google::Cloud::Scheduler::V1::Job#name name} cannot be the same as an
355
+ # existing job. If a name is not specified then the system will
356
+ # generate a random unique name that will be returned
357
+ # ({::Google::Cloud::Scheduler::V1::Job#name name}) in the response.
358
+ #
359
+ # @yield [response, operation] Access the result along with the RPC operation
360
+ # @yieldparam response [::Google::Cloud::Scheduler::V1::Job]
361
+ # @yieldparam operation [::GRPC::ActiveCall::Operation]
362
+ #
363
+ # @return [::Google::Cloud::Scheduler::V1::Job]
364
+ #
365
+ # @raise [::Google::Cloud::Error] if the RPC is aborted.
366
+ #
367
+ def create_job request, options = nil
368
+ raise ::ArgumentError, "request must be provided" if request.nil?
369
+
370
+ request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Scheduler::V1::CreateJobRequest
371
+
372
+ # Converts hash and nil to an options object
373
+ options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
374
+
375
+ # Customize the options with defaults
376
+ metadata = @config.rpcs.create_job.metadata.to_h
377
+
378
+ # Set x-goog-api-client and x-goog-user-project headers
379
+ metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
380
+ lib_name: @config.lib_name, lib_version: @config.lib_version,
381
+ gapic_version: ::Google::Cloud::Scheduler::V1::VERSION
382
+ metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
383
+
384
+ header_params = {
385
+ "parent" => request.parent
386
+ }
387
+ request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
388
+ metadata[:"x-goog-request-params"] ||= request_params_header
389
+
390
+ options.apply_defaults timeout: @config.rpcs.create_job.timeout,
391
+ metadata: metadata,
392
+ retry_policy: @config.rpcs.create_job.retry_policy
393
+ options.apply_defaults metadata: @config.metadata,
394
+ retry_policy: @config.retry_policy
395
+
396
+ @cloud_scheduler_stub.call_rpc :create_job, request, options: options do |response, operation|
397
+ yield response, operation if block_given?
398
+ return response
399
+ end
400
+ rescue ::GRPC::BadStatus => e
401
+ raise ::Google::Cloud::Error.from_error(e)
402
+ end
403
+
404
+ ##
405
+ # Updates a job.
406
+ #
407
+ # If successful, the updated {::Google::Cloud::Scheduler::V1::Job Job} is returned. If the job does
408
+ # not exist, `NOT_FOUND` is returned.
409
+ #
410
+ # If UpdateJob does not successfully return, it is possible for the
411
+ # job to be in an {::Google::Cloud::Scheduler::V1::Job::State::UPDATE_FAILED Job.State.UPDATE_FAILED} state. A job in this state may
412
+ # not be executed. If this happens, retry the UpdateJob request
413
+ # until a successful response is received.
414
+ #
415
+ # @overload update_job(request, options = nil)
416
+ # Pass arguments to `update_job` via a request object, either of type
417
+ # {::Google::Cloud::Scheduler::V1::UpdateJobRequest} or an equivalent Hash.
418
+ #
419
+ # @param request [::Google::Cloud::Scheduler::V1::UpdateJobRequest, ::Hash]
420
+ # A request object representing the call parameters. Required. To specify no
421
+ # parameters, or to keep all the default parameter values, pass an empty Hash.
422
+ # @param options [::Gapic::CallOptions, ::Hash]
423
+ # Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
424
+ #
425
+ # @overload update_job(job: nil, update_mask: nil)
426
+ # Pass arguments to `update_job` via keyword arguments. Note that at
427
+ # least one keyword argument is required. To specify no parameters, or to keep all
428
+ # the default parameter values, pass an empty Hash as a request object (see above).
429
+ #
430
+ # @param job [::Google::Cloud::Scheduler::V1::Job, ::Hash]
431
+ # Required. The new job properties. {::Google::Cloud::Scheduler::V1::Job#name name} must be specified.
432
+ #
433
+ # Output only fields cannot be modified using UpdateJob.
434
+ # Any value specified for an output only field will be ignored.
435
+ # @param update_mask [::Google::Protobuf::FieldMask, ::Hash]
436
+ # A mask used to specify which fields of the job are being updated.
437
+ #
438
+ # @yield [response, operation] Access the result along with the RPC operation
439
+ # @yieldparam response [::Google::Cloud::Scheduler::V1::Job]
440
+ # @yieldparam operation [::GRPC::ActiveCall::Operation]
441
+ #
442
+ # @return [::Google::Cloud::Scheduler::V1::Job]
443
+ #
444
+ # @raise [::Google::Cloud::Error] if the RPC is aborted.
445
+ #
446
+ def update_job request, options = nil
447
+ raise ::ArgumentError, "request must be provided" if request.nil?
448
+
449
+ request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Scheduler::V1::UpdateJobRequest
450
+
451
+ # Converts hash and nil to an options object
452
+ options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
453
+
454
+ # Customize the options with defaults
455
+ metadata = @config.rpcs.update_job.metadata.to_h
456
+
457
+ # Set x-goog-api-client and x-goog-user-project headers
458
+ metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
459
+ lib_name: @config.lib_name, lib_version: @config.lib_version,
460
+ gapic_version: ::Google::Cloud::Scheduler::V1::VERSION
461
+ metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
462
+
463
+ header_params = {
464
+ "job.name" => request.job.name
465
+ }
466
+ request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
467
+ metadata[:"x-goog-request-params"] ||= request_params_header
468
+
469
+ options.apply_defaults timeout: @config.rpcs.update_job.timeout,
470
+ metadata: metadata,
471
+ retry_policy: @config.rpcs.update_job.retry_policy
472
+ options.apply_defaults metadata: @config.metadata,
473
+ retry_policy: @config.retry_policy
474
+
475
+ @cloud_scheduler_stub.call_rpc :update_job, request, options: options do |response, operation|
476
+ yield response, operation if block_given?
477
+ return response
478
+ end
479
+ rescue ::GRPC::BadStatus => e
480
+ raise ::Google::Cloud::Error.from_error(e)
481
+ end
482
+
483
+ ##
484
+ # Deletes a job.
485
+ #
486
+ # @overload delete_job(request, options = nil)
487
+ # Pass arguments to `delete_job` via a request object, either of type
488
+ # {::Google::Cloud::Scheduler::V1::DeleteJobRequest} or an equivalent Hash.
489
+ #
490
+ # @param request [::Google::Cloud::Scheduler::V1::DeleteJobRequest, ::Hash]
491
+ # A request object representing the call parameters. Required. To specify no
492
+ # parameters, or to keep all the default parameter values, pass an empty Hash.
493
+ # @param options [::Gapic::CallOptions, ::Hash]
494
+ # Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
495
+ #
496
+ # @overload delete_job(name: nil)
497
+ # Pass arguments to `delete_job` via keyword arguments. Note that at
498
+ # least one keyword argument is required. To specify no parameters, or to keep all
499
+ # the default parameter values, pass an empty Hash as a request object (see above).
500
+ #
501
+ # @param name [::String]
502
+ # Required. The job name. For example:
503
+ # `projects/PROJECT_ID/locations/LOCATION_ID/jobs/JOB_ID`.
504
+ #
505
+ # @yield [response, operation] Access the result along with the RPC operation
506
+ # @yieldparam response [::Google::Protobuf::Empty]
507
+ # @yieldparam operation [::GRPC::ActiveCall::Operation]
508
+ #
509
+ # @return [::Google::Protobuf::Empty]
510
+ #
511
+ # @raise [::Google::Cloud::Error] if the RPC is aborted.
512
+ #
513
+ def delete_job request, options = nil
514
+ raise ::ArgumentError, "request must be provided" if request.nil?
515
+
516
+ request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Scheduler::V1::DeleteJobRequest
517
+
518
+ # Converts hash and nil to an options object
519
+ options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
520
+
521
+ # Customize the options with defaults
522
+ metadata = @config.rpcs.delete_job.metadata.to_h
523
+
524
+ # Set x-goog-api-client and x-goog-user-project headers
525
+ metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
526
+ lib_name: @config.lib_name, lib_version: @config.lib_version,
527
+ gapic_version: ::Google::Cloud::Scheduler::V1::VERSION
528
+ metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
529
+
530
+ header_params = {
531
+ "name" => request.name
532
+ }
533
+ request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
534
+ metadata[:"x-goog-request-params"] ||= request_params_header
535
+
536
+ options.apply_defaults timeout: @config.rpcs.delete_job.timeout,
537
+ metadata: metadata,
538
+ retry_policy: @config.rpcs.delete_job.retry_policy
539
+ options.apply_defaults metadata: @config.metadata,
540
+ retry_policy: @config.retry_policy
541
+
542
+ @cloud_scheduler_stub.call_rpc :delete_job, request, options: options do |response, operation|
543
+ yield response, operation if block_given?
544
+ return response
545
+ end
546
+ rescue ::GRPC::BadStatus => e
547
+ raise ::Google::Cloud::Error.from_error(e)
548
+ end
549
+
550
+ ##
551
+ # Pauses a job.
552
+ #
553
+ # If a job is paused then the system will stop executing the job
554
+ # until it is re-enabled via {::Google::Cloud::Scheduler::V1::CloudScheduler::Client#resume_job ResumeJob}. The
555
+ # state of the job is stored in {::Google::Cloud::Scheduler::V1::Job#state state}; if paused it
556
+ # will be set to {::Google::Cloud::Scheduler::V1::Job::State::PAUSED Job.State.PAUSED}. A job must be in {::Google::Cloud::Scheduler::V1::Job::State::ENABLED Job.State.ENABLED}
557
+ # to be paused.
558
+ #
559
+ # @overload pause_job(request, options = nil)
560
+ # Pass arguments to `pause_job` via a request object, either of type
561
+ # {::Google::Cloud::Scheduler::V1::PauseJobRequest} or an equivalent Hash.
562
+ #
563
+ # @param request [::Google::Cloud::Scheduler::V1::PauseJobRequest, ::Hash]
564
+ # A request object representing the call parameters. Required. To specify no
565
+ # parameters, or to keep all the default parameter values, pass an empty Hash.
566
+ # @param options [::Gapic::CallOptions, ::Hash]
567
+ # Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
568
+ #
569
+ # @overload pause_job(name: nil)
570
+ # Pass arguments to `pause_job` via keyword arguments. Note that at
571
+ # least one keyword argument is required. To specify no parameters, or to keep all
572
+ # the default parameter values, pass an empty Hash as a request object (see above).
573
+ #
574
+ # @param name [::String]
575
+ # Required. The job name. For example:
576
+ # `projects/PROJECT_ID/locations/LOCATION_ID/jobs/JOB_ID`.
577
+ #
578
+ # @yield [response, operation] Access the result along with the RPC operation
579
+ # @yieldparam response [::Google::Cloud::Scheduler::V1::Job]
580
+ # @yieldparam operation [::GRPC::ActiveCall::Operation]
581
+ #
582
+ # @return [::Google::Cloud::Scheduler::V1::Job]
583
+ #
584
+ # @raise [::Google::Cloud::Error] if the RPC is aborted.
585
+ #
586
+ def pause_job request, options = nil
587
+ raise ::ArgumentError, "request must be provided" if request.nil?
588
+
589
+ request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Scheduler::V1::PauseJobRequest
590
+
591
+ # Converts hash and nil to an options object
592
+ options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
593
+
594
+ # Customize the options with defaults
595
+ metadata = @config.rpcs.pause_job.metadata.to_h
596
+
597
+ # Set x-goog-api-client and x-goog-user-project headers
598
+ metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
599
+ lib_name: @config.lib_name, lib_version: @config.lib_version,
600
+ gapic_version: ::Google::Cloud::Scheduler::V1::VERSION
601
+ metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
602
+
603
+ header_params = {
604
+ "name" => request.name
605
+ }
606
+ request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
607
+ metadata[:"x-goog-request-params"] ||= request_params_header
608
+
609
+ options.apply_defaults timeout: @config.rpcs.pause_job.timeout,
610
+ metadata: metadata,
611
+ retry_policy: @config.rpcs.pause_job.retry_policy
612
+ options.apply_defaults metadata: @config.metadata,
613
+ retry_policy: @config.retry_policy
614
+
615
+ @cloud_scheduler_stub.call_rpc :pause_job, request, options: options do |response, operation|
616
+ yield response, operation if block_given?
617
+ return response
618
+ end
619
+ rescue ::GRPC::BadStatus => e
620
+ raise ::Google::Cloud::Error.from_error(e)
621
+ end
622
+
623
+ ##
624
+ # Resume a job.
625
+ #
626
+ # This method reenables a job after it has been {::Google::Cloud::Scheduler::V1::Job::State::PAUSED Job.State.PAUSED}. The
627
+ # state of a job is stored in {::Google::Cloud::Scheduler::V1::Job#state Job.state}; after calling this method it
628
+ # will be set to {::Google::Cloud::Scheduler::V1::Job::State::ENABLED Job.State.ENABLED}. A job must be in
629
+ # {::Google::Cloud::Scheduler::V1::Job::State::PAUSED Job.State.PAUSED} to be resumed.
630
+ #
631
+ # @overload resume_job(request, options = nil)
632
+ # Pass arguments to `resume_job` via a request object, either of type
633
+ # {::Google::Cloud::Scheduler::V1::ResumeJobRequest} or an equivalent Hash.
634
+ #
635
+ # @param request [::Google::Cloud::Scheduler::V1::ResumeJobRequest, ::Hash]
636
+ # A request object representing the call parameters. Required. To specify no
637
+ # parameters, or to keep all the default parameter values, pass an empty Hash.
638
+ # @param options [::Gapic::CallOptions, ::Hash]
639
+ # Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
640
+ #
641
+ # @overload resume_job(name: nil)
642
+ # Pass arguments to `resume_job` via keyword arguments. Note that at
643
+ # least one keyword argument is required. To specify no parameters, or to keep all
644
+ # the default parameter values, pass an empty Hash as a request object (see above).
645
+ #
646
+ # @param name [::String]
647
+ # Required. The job name. For example:
648
+ # `projects/PROJECT_ID/locations/LOCATION_ID/jobs/JOB_ID`.
649
+ #
650
+ # @yield [response, operation] Access the result along with the RPC operation
651
+ # @yieldparam response [::Google::Cloud::Scheduler::V1::Job]
652
+ # @yieldparam operation [::GRPC::ActiveCall::Operation]
653
+ #
654
+ # @return [::Google::Cloud::Scheduler::V1::Job]
655
+ #
656
+ # @raise [::Google::Cloud::Error] if the RPC is aborted.
657
+ #
658
+ def resume_job request, options = nil
659
+ raise ::ArgumentError, "request must be provided" if request.nil?
660
+
661
+ request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Scheduler::V1::ResumeJobRequest
662
+
663
+ # Converts hash and nil to an options object
664
+ options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
665
+
666
+ # Customize the options with defaults
667
+ metadata = @config.rpcs.resume_job.metadata.to_h
668
+
669
+ # Set x-goog-api-client and x-goog-user-project headers
670
+ metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
671
+ lib_name: @config.lib_name, lib_version: @config.lib_version,
672
+ gapic_version: ::Google::Cloud::Scheduler::V1::VERSION
673
+ metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
674
+
675
+ header_params = {
676
+ "name" => request.name
677
+ }
678
+ request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
679
+ metadata[:"x-goog-request-params"] ||= request_params_header
680
+
681
+ options.apply_defaults timeout: @config.rpcs.resume_job.timeout,
682
+ metadata: metadata,
683
+ retry_policy: @config.rpcs.resume_job.retry_policy
684
+ options.apply_defaults metadata: @config.metadata,
685
+ retry_policy: @config.retry_policy
686
+
687
+ @cloud_scheduler_stub.call_rpc :resume_job, request, options: options do |response, operation|
688
+ yield response, operation if block_given?
689
+ return response
690
+ end
691
+ rescue ::GRPC::BadStatus => e
692
+ raise ::Google::Cloud::Error.from_error(e)
693
+ end
694
+
695
+ ##
696
+ # Forces a job to run now.
697
+ #
698
+ # When this method is called, Cloud Scheduler will dispatch the job, even
699
+ # if the job is already running.
700
+ #
701
+ # @overload run_job(request, options = nil)
702
+ # Pass arguments to `run_job` via a request object, either of type
703
+ # {::Google::Cloud::Scheduler::V1::RunJobRequest} or an equivalent Hash.
704
+ #
705
+ # @param request [::Google::Cloud::Scheduler::V1::RunJobRequest, ::Hash]
706
+ # A request object representing the call parameters. Required. To specify no
707
+ # parameters, or to keep all the default parameter values, pass an empty Hash.
708
+ # @param options [::Gapic::CallOptions, ::Hash]
709
+ # Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
710
+ #
711
+ # @overload run_job(name: nil)
712
+ # Pass arguments to `run_job` via keyword arguments. Note that at
713
+ # least one keyword argument is required. To specify no parameters, or to keep all
714
+ # the default parameter values, pass an empty Hash as a request object (see above).
715
+ #
716
+ # @param name [::String]
717
+ # Required. The job name. For example:
718
+ # `projects/PROJECT_ID/locations/LOCATION_ID/jobs/JOB_ID`.
719
+ #
720
+ # @yield [response, operation] Access the result along with the RPC operation
721
+ # @yieldparam response [::Google::Cloud::Scheduler::V1::Job]
722
+ # @yieldparam operation [::GRPC::ActiveCall::Operation]
723
+ #
724
+ # @return [::Google::Cloud::Scheduler::V1::Job]
725
+ #
726
+ # @raise [::Google::Cloud::Error] if the RPC is aborted.
727
+ #
728
+ def run_job request, options = nil
729
+ raise ::ArgumentError, "request must be provided" if request.nil?
730
+
731
+ request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Scheduler::V1::RunJobRequest
732
+
733
+ # Converts hash and nil to an options object
734
+ options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
735
+
736
+ # Customize the options with defaults
737
+ metadata = @config.rpcs.run_job.metadata.to_h
738
+
739
+ # Set x-goog-api-client and x-goog-user-project headers
740
+ metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
741
+ lib_name: @config.lib_name, lib_version: @config.lib_version,
742
+ gapic_version: ::Google::Cloud::Scheduler::V1::VERSION
743
+ metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
744
+
745
+ header_params = {
746
+ "name" => request.name
747
+ }
748
+ request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
749
+ metadata[:"x-goog-request-params"] ||= request_params_header
750
+
751
+ options.apply_defaults timeout: @config.rpcs.run_job.timeout,
752
+ metadata: metadata,
753
+ retry_policy: @config.rpcs.run_job.retry_policy
754
+ options.apply_defaults metadata: @config.metadata,
755
+ retry_policy: @config.retry_policy
756
+
757
+ @cloud_scheduler_stub.call_rpc :run_job, request, options: options do |response, operation|
758
+ yield response, operation if block_given?
759
+ return response
760
+ end
761
+ rescue ::GRPC::BadStatus => e
762
+ raise ::Google::Cloud::Error.from_error(e)
763
+ end
764
+
765
+ ##
766
+ # Configuration class for the CloudScheduler API.
767
+ #
768
+ # This class represents the configuration for CloudScheduler,
769
+ # providing control over timeouts, retry behavior, logging, transport
770
+ # parameters, and other low-level controls. Certain parameters can also be
771
+ # applied individually to specific RPCs. See
772
+ # {::Google::Cloud::Scheduler::V1::CloudScheduler::Client::Configuration::Rpcs}
773
+ # for a list of RPCs that can be configured independently.
774
+ #
775
+ # Configuration can be applied globally to all clients, or to a single client
776
+ # on construction.
777
+ #
778
+ # # Examples
779
+ #
780
+ # To modify the global config, setting the timeout for list_jobs
781
+ # to 20 seconds, and all remaining timeouts to 10 seconds:
782
+ #
783
+ # ::Google::Cloud::Scheduler::V1::CloudScheduler::Client.configure do |config|
784
+ # config.timeout = 10.0
785
+ # config.rpcs.list_jobs.timeout = 20.0
786
+ # end
787
+ #
788
+ # To apply the above configuration only to a new client:
789
+ #
790
+ # client = ::Google::Cloud::Scheduler::V1::CloudScheduler::Client.new do |config|
791
+ # config.timeout = 10.0
792
+ # config.rpcs.list_jobs.timeout = 20.0
793
+ # end
794
+ #
795
+ # @!attribute [rw] endpoint
796
+ # The hostname or hostname:port of the service endpoint.
797
+ # Defaults to `"cloudscheduler.googleapis.com"`.
798
+ # @return [::String]
799
+ # @!attribute [rw] credentials
800
+ # Credentials to send with calls. You may provide any of the following types:
801
+ # * (`String`) The path to a service account key file in JSON format
802
+ # * (`Hash`) A service account key as a Hash
803
+ # * (`Google::Auth::Credentials`) A googleauth credentials object
804
+ # (see the [googleauth docs](https://googleapis.dev/ruby/googleauth/latest/index.html))
805
+ # * (`Signet::OAuth2::Client`) A signet oauth2 client object
806
+ # (see the [signet docs](https://googleapis.dev/ruby/signet/latest/Signet/OAuth2/Client.html))
807
+ # * (`GRPC::Core::Channel`) a gRPC channel with included credentials
808
+ # * (`GRPC::Core::ChannelCredentials`) a gRPC credentails object
809
+ # * (`nil`) indicating no credentials
810
+ # @return [::Object]
811
+ # @!attribute [rw] scope
812
+ # The OAuth scopes
813
+ # @return [::Array<::String>]
814
+ # @!attribute [rw] lib_name
815
+ # The library name as recorded in instrumentation and logging
816
+ # @return [::String]
817
+ # @!attribute [rw] lib_version
818
+ # The library version as recorded in instrumentation and logging
819
+ # @return [::String]
820
+ # @!attribute [rw] channel_args
821
+ # Extra parameters passed to the gRPC channel. Note: this is ignored if a
822
+ # `GRPC::Core::Channel` object is provided as the credential.
823
+ # @return [::Hash]
824
+ # @!attribute [rw] interceptors
825
+ # An array of interceptors that are run before calls are executed.
826
+ # @return [::Array<::GRPC::ClientInterceptor>]
827
+ # @!attribute [rw] timeout
828
+ # The call timeout in seconds.
829
+ # @return [::Numeric]
830
+ # @!attribute [rw] metadata
831
+ # Additional gRPC headers to be sent with the call.
832
+ # @return [::Hash{::Symbol=>::String}]
833
+ # @!attribute [rw] retry_policy
834
+ # The retry policy. The value is a hash with the following keys:
835
+ # * `:initial_delay` (*type:* `Numeric`) - The initial delay in seconds.
836
+ # * `:max_delay` (*type:* `Numeric`) - The max delay in seconds.
837
+ # * `:multiplier` (*type:* `Numeric`) - The incremental backoff multiplier.
838
+ # * `:retry_codes` (*type:* `Array<String>`) - The error codes that should
839
+ # trigger a retry.
840
+ # @return [::Hash]
841
+ #
842
+ class Configuration
843
+ extend ::Gapic::Config
844
+
845
+ config_attr :endpoint, "cloudscheduler.googleapis.com", String
846
+ config_attr :credentials, nil do |value|
847
+ allowed = [::String, ::Hash, ::Proc, ::Google::Auth::Credentials, ::Signet::OAuth2::Client, nil]
848
+ allowed += [::GRPC::Core::Channel, ::GRPC::Core::ChannelCredentials] if defined? ::GRPC
849
+ allowed.any? { |klass| klass === value }
850
+ end
851
+ config_attr :scope, nil, ::String, ::Array, nil
852
+ config_attr :lib_name, nil, ::String, nil
853
+ config_attr :lib_version, nil, ::String, nil
854
+ config_attr(:channel_args, { "grpc.service_config_disable_resolution"=>1 }, ::Hash, nil)
855
+ config_attr :interceptors, nil, ::Array, nil
856
+ config_attr :timeout, nil, ::Numeric, nil
857
+ config_attr :metadata, nil, ::Hash, nil
858
+ config_attr :retry_policy, nil, ::Hash, Proc, nil
859
+
860
+ # @private
861
+ def initialize parent_config = nil
862
+ @parent_config = parent_config unless parent_config.nil?
863
+
864
+ yield self if block_given?
865
+ end
866
+
867
+ ##
868
+ # Configurations for individual RPCs
869
+ # @return [Rpcs]
870
+ #
871
+ def rpcs
872
+ @rpcs ||= begin
873
+ parent_rpcs = nil
874
+ parent_rpcs = @parent_config.rpcs if @parent_config&.respond_to? :rpcs
875
+ Rpcs.new parent_rpcs
876
+ end
877
+ end
878
+
879
+ ##
880
+ # Configuration RPC class for the CloudScheduler API.
881
+ #
882
+ # Includes fields providing the configuration for each RPC in this service.
883
+ # Each configuration object is of type `Gapic::Config::Method` and includes
884
+ # the following configuration fields:
885
+ #
886
+ # * `timeout` (*type:* `Numeric`) - The call timeout in milliseconds
887
+ # * `metadata` (*type:* `Hash{Symbol=>String}`) - Additional gRPC headers
888
+ # * `retry_policy (*type:* `Hash`) - The retry policy. The policy fields
889
+ # include the following keys:
890
+ # * `:initial_delay` (*type:* `Numeric`) - The initial delay in seconds.
891
+ # * `:max_delay` (*type:* `Numeric`) - The max delay in seconds.
892
+ # * `:multiplier` (*type:* `Numeric`) - The incremental backoff multiplier.
893
+ # * `:retry_codes` (*type:* `Array<String>`) - The error codes that should
894
+ # trigger a retry.
895
+ #
896
+ class Rpcs
897
+ ##
898
+ # RPC-specific configuration for `list_jobs`
899
+ # @return [::Gapic::Config::Method]
900
+ #
901
+ attr_reader :list_jobs
902
+ ##
903
+ # RPC-specific configuration for `get_job`
904
+ # @return [::Gapic::Config::Method]
905
+ #
906
+ attr_reader :get_job
907
+ ##
908
+ # RPC-specific configuration for `create_job`
909
+ # @return [::Gapic::Config::Method]
910
+ #
911
+ attr_reader :create_job
912
+ ##
913
+ # RPC-specific configuration for `update_job`
914
+ # @return [::Gapic::Config::Method]
915
+ #
916
+ attr_reader :update_job
917
+ ##
918
+ # RPC-specific configuration for `delete_job`
919
+ # @return [::Gapic::Config::Method]
920
+ #
921
+ attr_reader :delete_job
922
+ ##
923
+ # RPC-specific configuration for `pause_job`
924
+ # @return [::Gapic::Config::Method]
925
+ #
926
+ attr_reader :pause_job
927
+ ##
928
+ # RPC-specific configuration for `resume_job`
929
+ # @return [::Gapic::Config::Method]
930
+ #
931
+ attr_reader :resume_job
932
+ ##
933
+ # RPC-specific configuration for `run_job`
934
+ # @return [::Gapic::Config::Method]
935
+ #
936
+ attr_reader :run_job
937
+
938
+ # @private
939
+ def initialize parent_rpcs = nil
940
+ list_jobs_config = parent_rpcs&.list_jobs if parent_rpcs&.respond_to? :list_jobs
941
+ @list_jobs = ::Gapic::Config::Method.new list_jobs_config
942
+ get_job_config = parent_rpcs&.get_job if parent_rpcs&.respond_to? :get_job
943
+ @get_job = ::Gapic::Config::Method.new get_job_config
944
+ create_job_config = parent_rpcs&.create_job if parent_rpcs&.respond_to? :create_job
945
+ @create_job = ::Gapic::Config::Method.new create_job_config
946
+ update_job_config = parent_rpcs&.update_job if parent_rpcs&.respond_to? :update_job
947
+ @update_job = ::Gapic::Config::Method.new update_job_config
948
+ delete_job_config = parent_rpcs&.delete_job if parent_rpcs&.respond_to? :delete_job
949
+ @delete_job = ::Gapic::Config::Method.new delete_job_config
950
+ pause_job_config = parent_rpcs&.pause_job if parent_rpcs&.respond_to? :pause_job
951
+ @pause_job = ::Gapic::Config::Method.new pause_job_config
952
+ resume_job_config = parent_rpcs&.resume_job if parent_rpcs&.respond_to? :resume_job
953
+ @resume_job = ::Gapic::Config::Method.new resume_job_config
954
+ run_job_config = parent_rpcs&.run_job if parent_rpcs&.respond_to? :run_job
955
+ @run_job = ::Gapic::Config::Method.new run_job_config
956
+
957
+ yield self if block_given?
958
+ end
959
+ end
960
+ end
961
+ end
962
+ end
963
+ end
964
+ end
965
+ end
966
+ end