From e5c98bcb9679fa051b78d931825f2bd25ab2fec2 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Tue, 10 Jun 2025 13:35:59 +0000 Subject: [PATCH 01/17] changes working --- .../samples/Gemfile | 39 +++++++++ .../samples/acceptance/batch_job_test.rb | 86 +++++++++++++++++++ .../samples/acceptance/helper.rb | 77 +++++++++++++++++ .../samples/storage_batch_cancel_job.rb | 33 +++++++ .../samples/storage_batch_create_job.rb | 60 +++++++++++++ .../samples/storage_batch_delete_job.rb | 33 +++++++ .../samples/storage_batch_get_job.rb | 33 +++++++ .../samples/storage_batch_get_job_status.rb | 33 +++++++ .../samples/storage_batch_list_job.rb | 32 +++++++ 9 files changed, 426 insertions(+) create mode 100644 google-cloud-storage_batch_operations/samples/Gemfile create mode 100644 google-cloud-storage_batch_operations/samples/acceptance/batch_job_test.rb create mode 100644 google-cloud-storage_batch_operations/samples/acceptance/helper.rb create mode 100644 google-cloud-storage_batch_operations/samples/storage_batch_cancel_job.rb create mode 100644 google-cloud-storage_batch_operations/samples/storage_batch_create_job.rb create mode 100644 google-cloud-storage_batch_operations/samples/storage_batch_delete_job.rb create mode 100644 google-cloud-storage_batch_operations/samples/storage_batch_get_job.rb create mode 100644 google-cloud-storage_batch_operations/samples/storage_batch_get_job_status.rb create mode 100644 google-cloud-storage_batch_operations/samples/storage_batch_list_job.rb diff --git a/google-cloud-storage_batch_operations/samples/Gemfile b/google-cloud-storage_batch_operations/samples/Gemfile new file mode 100644 index 000000000000..3647efa986f4 --- /dev/null +++ b/google-cloud-storage_batch_operations/samples/Gemfile @@ -0,0 +1,39 @@ +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# [START storage_dependencies] +source "https://rubygems.org" + +# [END storage_dependencies] + +if ENV["GOOGLE_CLOUD_SAMPLES_TEST"] == "master" + gem "google-cloud-kms", group: :test, path: "../../google-cloud-kms" + gem "google-cloud-storage", path: "../../google-cloud-storage" + gem "google-cloud-storage_batch_operations", path: "../../google-cloud-storage_batch_operations" +else + # [START storage_dependencies] + gem "google-cloud-kms" + gem "google-cloud-storage" + gem "google-cloud-storage_batch_operations" + # [END storage_dependencies] +end + +group :test do + gem "google-style", "~> 1.30.0" + gem "minitest", "~> 5.14" + gem "minitest-focus", "~> 1.1" + gem "minitest-hooks", "~> 1.5" + gem "rake" +end +gem 'yard' diff --git a/google-cloud-storage_batch_operations/samples/acceptance/batch_job_test.rb b/google-cloud-storage_batch_operations/samples/acceptance/batch_job_test.rb new file mode 100644 index 000000000000..5ba2cfccff8b --- /dev/null +++ b/google-cloud-storage_batch_operations/samples/acceptance/batch_job_test.rb @@ -0,0 +1,86 @@ +# Copyright 2025 Google LLC +# Licensed under the Apache License, Version 2.0 + +require_relative "helper" +require_relative "../storage_batch_create_job" +require_relative "../storage_batch_delete_job" +require_relative "../storage_batch_cancel_job" +require_relative "../storage_batch_list_job" +require_relative "../storage_batch_get_job" +require_relative "../storage_batch_get_job_status" + +describe "Batch jobs Snippets" do + let(:storage_client) { Google::Cloud::Storage.new } + let(:project_name) { storage_client.project } + let(:parent) { "projects/#{project_name}/locations/global" } + let(:bucket) { @bucket } + let(:file_content) { "some content" } + let(:remote_file_name) { "ruby_file_#{SecureRandom.hex}" } + let(:job_name) { @job_name } + + + before :all do + @bucket = create_bucket_helper random_bucket_name + end + + after :all do + delete_bucket_helper @bucket.name + end + + def create_test_job(my_job) + bucket.create_file StringIO.new(file_content), remote_file_name + create_job bucket_name: bucket.name, prefix: "ruby_file", job_name: my_job, parent: parent + end + + describe "storage batch manage operations" do + before do + @job_name= "ruby-sbo-job-#{SecureRandom.hex}" + create_test_job(job_name) + end + + it "lists jobs and includes the created job" do + out, _err = capture_io { list_job parent: parent } + assert_includes out, @job_name, "Expected job name not found in the result list" + end + + + it "fetches the details of a job" do + assert_output parent+"/jobs/"+job_name+"\n" do + get_job parent: parent, job_name: job_name + end + end + + it "cancels a job" do + assert_output "The job is canceled.\n" do + cancel_job parent: parent, job_name: job_name + end + end + + end + + describe "Delete storage batch ops" do + before do + @job_name= "ruby-sbo-job-#{SecureRandom.hex}" + create_test_job(job_name) + end + it "deletes a job" do + retry_job_status do + get_job_status parent: parent, job_name: job_name + end + assert_output "The job is deleted.\n" do + delete_job parent: parent, job_name: job_name + end + end + end + + describe "creates a storage batch ops" do + it "creates a job" do + assert_output "The job is created.\n" do + @job_name= "ruby-sbo-job-#{SecureRandom.hex}" + + create_test_job(job_name) + end + end + end + +end diff --git a/google-cloud-storage_batch_operations/samples/acceptance/helper.rb b/google-cloud-storage_batch_operations/samples/acceptance/helper.rb new file mode 100644 index 000000000000..78ef6bb37524 --- /dev/null +++ b/google-cloud-storage_batch_operations/samples/acceptance/helper.rb @@ -0,0 +1,77 @@ +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +require "google/cloud/errors" +require "google/cloud/kms" +require "google/cloud/storage" +require "minitest/autorun" +require "minitest/focus" +require "minitest/hooks/default" +require "net/http" +require "time" +require "securerandom" +require "uri" +require "ostruct" + + +def fixture_bucket + storage_client = Google::Cloud::Storage.new + storage_client.bucket($fixture_bucket_name) || + retry_resource_exhaustion { storage_client.create_bucket $fixture_bucket_name } +end + +def create_bucket_helper bucket_name + storage_client = Google::Cloud::Storage.new + retry_resource_exhaustion do + storage_client.create_bucket bucket_name + end +end + +def delete_bucket_helper bucket_name + storage_client = Google::Cloud::Storage.new + retry_resource_exhaustion do + bucket = storage_client.bucket bucket_name + return unless bucket + + bucket.files.each(&:delete) + bucket.delete + end +end + +def retry_job_status + 5.times do + if yield == :RUNNING + puts "Job in Running status Gonna try again" + sleep rand(5..9) + end + end +end + +def retry_resource_exhaustion + 5.times do + return yield + rescue Google::Cloud::ResourceExhaustedError => e + puts "\n#{e} Gonna try again" + sleep rand(10..16) + rescue StandardError => e + puts "\n#{e}" + raise e + end + raise Google::Cloud::ResourceExhaustedError, "Maybe take a break from creating and deleting buckets for a bit" +end + +def random_bucket_name + t = Time.now.utc.iso8601.gsub ":", "-" + "ruby-storage-samples-test-#{t}-#{SecureRandom.hex 4}".downcase +end diff --git a/google-cloud-storage_batch_operations/samples/storage_batch_cancel_job.rb b/google-cloud-storage_batch_operations/samples/storage_batch_cancel_job.rb new file mode 100644 index 000000000000..d909bfb709a9 --- /dev/null +++ b/google-cloud-storage_batch_operations/samples/storage_batch_cancel_job.rb @@ -0,0 +1,33 @@ +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# [START storage_batch_cancel_job] +def cancel_job parent:, job_name: + # The ID of your GCS bucket + # bucket_name = "your-unique-bucket-name" + + # The ID of your GCS object + # file_name = "your-file-name" + + require "google/cloud/storage_batch_operations/v1" + + client = Google::Cloud::StorageBatchOperations::V1::StorageBatchOperations::Client.new + + request = Google::Cloud::StorageBatchOperations::V1::CancelJobRequest.new name: "#{parent}/jobs/#{job_name}" + result = client.cancel_job request + puts result.is_a?(Google::Cloud::StorageBatchOperations::V1::CancelJobResponse) ? "The job is canceled." : "The job is not canceled." +end +# [END storage_batch_cancel_job] + +cancel_job parent: ARGV.shift, job_name: ARGV.shift if $PROGRAM_NAME == __FILE__ diff --git a/google-cloud-storage_batch_operations/samples/storage_batch_create_job.rb b/google-cloud-storage_batch_operations/samples/storage_batch_create_job.rb new file mode 100644 index 000000000000..607d9c885d98 --- /dev/null +++ b/google-cloud-storage_batch_operations/samples/storage_batch_create_job.rb @@ -0,0 +1,60 @@ +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# [START storage_batch_create_job] +def create_job bucket_name:, prefix:, job_name:, parent: + # The ID of your GCS bucket + # bucket_name = "your-unique-bucket-name" + + # The ID of your GCS object + # file_name = "your-file-name" + + require "google/cloud/storage_batch_operations/v1" + + client = Google::Cloud::StorageBatchOperations::V1::StorageBatchOperations::Client.new + + prefix_list = Google::Cloud::StorageBatchOperations::V1::PrefixList.new( + included_object_prefixes: [prefix] + ) + + bucket = Google::Cloud::StorageBatchOperations::V1::BucketList::Bucket.new( + bucket: bucket_name, + prefix_list: prefix_list + ) + + bucket_list = Google::Cloud::StorageBatchOperations::V1::BucketList.new( + buckets: [bucket] + ) + + # Define the delete operation + delete_object = Google::Cloud::StorageBatchOperations::V1::DeleteObject.new( + permanent_object_deletion_enabled: false + ) + + # Build the job + job = Google::Cloud::StorageBatchOperations::V1::Job.new( + name: job_name, + bucket_list: bucket_list, + delete_object: delete_object + ) + + request = Google::Cloud::StorageBatchOperations::V1::CreateJobRequest.new(parent: parent, job_id: job_name, job: job ) + result = client.create_job request + + puts result.is_a?(Gapic::Operation) ? "The job is created." : "The job is not created." + +end +# [END storage_batch_create_job] + +create_job bucket_name: ARGV.shift, prefix: ARGV.shift, job_name: ARGV.shift, parent: ARGV.shift, job_type: ARGV.shift if $PROGRAM_NAME == __FILE__ diff --git a/google-cloud-storage_batch_operations/samples/storage_batch_delete_job.rb b/google-cloud-storage_batch_operations/samples/storage_batch_delete_job.rb new file mode 100644 index 000000000000..bc40fabf0ebb --- /dev/null +++ b/google-cloud-storage_batch_operations/samples/storage_batch_delete_job.rb @@ -0,0 +1,33 @@ +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# [START storage_batch_delete_job] +def delete_job parent:, job_name: + # The parent location for your job + # parent = "projects/your-project-id/locations/your-location" + + # The name of your Storage batch operation job + # job_name = "your-job-name" + + require "google/cloud/storage_batch_operations/v1" + + client = Google::Cloud::StorageBatchOperations::V1::StorageBatchOperations::Client.new + request = Google::Cloud::StorageBatchOperations::V1::DeleteJobRequest.new name: "#{parent}/jobs/#{job_name}" + result = client.delete_job request + puts result.is_a?(Google::Protobuf::Empty) ? "The job is deleted." : "The job is not deleted." + +end +# [END storage_batch_delete_job] + +delete_job parent: ARGV.shift, job_name: ARGV.shift if $PROGRAM_NAME == __FILE__ diff --git a/google-cloud-storage_batch_operations/samples/storage_batch_get_job.rb b/google-cloud-storage_batch_operations/samples/storage_batch_get_job.rb new file mode 100644 index 000000000000..b01c453491ba --- /dev/null +++ b/google-cloud-storage_batch_operations/samples/storage_batch_get_job.rb @@ -0,0 +1,33 @@ + +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# [START storage_batch_get_job] +def get_job parent:, job_name: + # The parent location for your job + # parent = "projects/your-project-id/locations/your-location" + + # The name of your Storage batch operation job + # job_name = "your-job-name" + + require "google/cloud/storage_batch_operations/v1" + + client = Google::Cloud::StorageBatchOperations::V1::StorageBatchOperations::Client.new + request = Google::Cloud::StorageBatchOperations::V1::GetJobRequest.new name: "#{parent}/jobs/#{job_name}" + result = client.get_job request + puts result.name +end +# [END storage_batch_get_job] + +get_job parent: ARGV.shift, job_name: ARGV.shift if $PROGRAM_NAME == __FILE__ diff --git a/google-cloud-storage_batch_operations/samples/storage_batch_get_job_status.rb b/google-cloud-storage_batch_operations/samples/storage_batch_get_job_status.rb new file mode 100644 index 000000000000..11d101a31a7b --- /dev/null +++ b/google-cloud-storage_batch_operations/samples/storage_batch_get_job_status.rb @@ -0,0 +1,33 @@ + +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# [START storage_batch_get_job_status] +def get_job_status parent:, job_name: + # The parent location for your job + # parent = "projects/your-project-id/locations/your-location" + + # The name of your Storage batch operation job + # job_name = "your-job-name" + + require "google/cloud/storage_batch_operations/v1" + + client = Google::Cloud::StorageBatchOperations::V1::StorageBatchOperations::Client.new + request = Google::Cloud::StorageBatchOperations::V1::GetJobRequest.new name: "#{parent}/jobs/#{job_name}" + result = client.get_job request + result.state +end +# [END storage_batch_get_job_status] + +get_job parent: ARGV.shift, job_name: ARGV.shift if $PROGRAM_NAME == __FILE__ diff --git a/google-cloud-storage_batch_operations/samples/storage_batch_list_job.rb b/google-cloud-storage_batch_operations/samples/storage_batch_list_job.rb new file mode 100644 index 000000000000..4c264a97aac9 --- /dev/null +++ b/google-cloud-storage_batch_operations/samples/storage_batch_list_job.rb @@ -0,0 +1,32 @@ +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# [START storage_batch_list_job] +def list_job parent: + # The parent location for your job + # parent = "projects/your-project-id/locations/your-location" + + require "google/cloud/storage_batch_operations/v1" + client = Google::Cloud::StorageBatchOperations::V1::StorageBatchOperations::Client.new + + request = Google::Cloud::StorageBatchOperations::V1::ListJobsRequest.new parent: parent, page_size: 10 + result = client.list_jobs request + result.each do |job| + puts "Job name: #{job.name}" + end + +end +# [END storage_batch_list_job] + +delete_job parent: ARGV.shift, job_name: ARGV.shift if $PROGRAM_NAME == __FILE__ From c530e2819524c198a74af8ea2a08fe8d4bb56ac8 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Wed, 11 Jun 2025 17:34:23 +0000 Subject: [PATCH 02/17] fixing lint --- .../samples/Gemfile | 2 +- .../samples/acceptance/batch_job_test.rb | 25 ++++++++----------- .../samples/acceptance/helper.rb | 6 ----- .../samples/storage_batch_cancel_job.rb | 8 +++--- .../samples/storage_batch_create_job.rb | 13 +++++++--- .../samples/storage_batch_delete_job.rb | 1 - .../samples/storage_batch_get_job.rb | 1 - .../samples/storage_batch_get_job_status.rb | 1 - .../samples/storage_batch_list_job.rb | 1 - 9 files changed, 25 insertions(+), 33 deletions(-) diff --git a/google-cloud-storage_batch_operations/samples/Gemfile b/google-cloud-storage_batch_operations/samples/Gemfile index 3647efa986f4..cc1abc83d299 100644 --- a/google-cloud-storage_batch_operations/samples/Gemfile +++ b/google-cloud-storage_batch_operations/samples/Gemfile @@ -36,4 +36,4 @@ group :test do gem "minitest-hooks", "~> 1.5" gem "rake" end -gem 'yard' +gem "yard" diff --git a/google-cloud-storage_batch_operations/samples/acceptance/batch_job_test.rb b/google-cloud-storage_batch_operations/samples/acceptance/batch_job_test.rb index 5ba2cfccff8b..19e2cfb53544 100644 --- a/google-cloud-storage_batch_operations/samples/acceptance/batch_job_test.rb +++ b/google-cloud-storage_batch_operations/samples/acceptance/batch_job_test.rb @@ -16,7 +16,7 @@ let(:bucket) { @bucket } let(:file_content) { "some content" } let(:remote_file_name) { "ruby_file_#{SecureRandom.hex}" } - let(:job_name) { @job_name } + let(:job_name) { @job_name } before :all do @@ -27,25 +27,24 @@ delete_bucket_helper @bucket.name end - def create_test_job(my_job) + def create_test_job my_job bucket.create_file StringIO.new(file_content), remote_file_name create_job bucket_name: bucket.name, prefix: "ruby_file", job_name: my_job, parent: parent end describe "storage batch manage operations" do - before do - @job_name= "ruby-sbo-job-#{SecureRandom.hex}" - create_test_job(job_name) - end + before do + @job_name = "ruby-sbo-job-#{SecureRandom.hex}" + create_test_job job_name + end it "lists jobs and includes the created job" do out, _err = capture_io { list_job parent: parent } assert_includes out, @job_name, "Expected job name not found in the result list" end - it "fetches the details of a job" do - assert_output parent+"/jobs/"+job_name+"\n" do + assert_output "#{parent}/jobs/#{job_name}\n" do get_job parent: parent, job_name: job_name end end @@ -55,13 +54,12 @@ def create_test_job(my_job) cancel_job parent: parent, job_name: job_name end end - end describe "Delete storage batch ops" do before do - @job_name= "ruby-sbo-job-#{SecureRandom.hex}" - create_test_job(job_name) + @job_name = "ruby-sbo-job-#{SecureRandom.hex}" + create_test_job job_name end it "deletes a job" do retry_job_status do @@ -76,11 +74,10 @@ def create_test_job(my_job) describe "creates a storage batch ops" do it "creates a job" do assert_output "The job is created.\n" do - @job_name= "ruby-sbo-job-#{SecureRandom.hex}" + @job_name = "ruby-sbo-job-#{SecureRandom.hex}" - create_test_job(job_name) + create_test_job job_name end end end - end diff --git a/google-cloud-storage_batch_operations/samples/acceptance/helper.rb b/google-cloud-storage_batch_operations/samples/acceptance/helper.rb index 78ef6bb37524..7f86723c96cf 100644 --- a/google-cloud-storage_batch_operations/samples/acceptance/helper.rb +++ b/google-cloud-storage_batch_operations/samples/acceptance/helper.rb @@ -25,12 +25,6 @@ require "ostruct" -def fixture_bucket - storage_client = Google::Cloud::Storage.new - storage_client.bucket($fixture_bucket_name) || - retry_resource_exhaustion { storage_client.create_bucket $fixture_bucket_name } -end - def create_bucket_helper bucket_name storage_client = Google::Cloud::Storage.new retry_resource_exhaustion do diff --git a/google-cloud-storage_batch_operations/samples/storage_batch_cancel_job.rb b/google-cloud-storage_batch_operations/samples/storage_batch_cancel_job.rb index d909bfb709a9..1e308d6e2b2d 100644 --- a/google-cloud-storage_batch_operations/samples/storage_batch_cancel_job.rb +++ b/google-cloud-storage_batch_operations/samples/storage_batch_cancel_job.rb @@ -14,11 +14,11 @@ # [START storage_batch_cancel_job] def cancel_job parent:, job_name: - # The ID of your GCS bucket - # bucket_name = "your-unique-bucket-name" + # The parent location for your job + # parent = "projects/your-project-id/locations/your-location" - # The ID of your GCS object - # file_name = "your-file-name" + # The name of your Storage batch operation job + # job_name = "your-job-name" require "google/cloud/storage_batch_operations/v1" diff --git a/google-cloud-storage_batch_operations/samples/storage_batch_create_job.rb b/google-cloud-storage_batch_operations/samples/storage_batch_create_job.rb index 607d9c885d98..94c622ad3090 100644 --- a/google-cloud-storage_batch_operations/samples/storage_batch_create_job.rb +++ b/google-cloud-storage_batch_operations/samples/storage_batch_create_job.rb @@ -17,8 +17,14 @@ def create_job bucket_name:, prefix:, job_name:, parent: # The ID of your GCS bucket # bucket_name = "your-unique-bucket-name" - # The ID of your GCS object - # file_name = "your-file-name" + # Prefix is the first part of filename on which job has to be executed + # prefix = 'test' + + # The parent location for your job + # parent = "projects/your-project-id/locations/your-location" + + # The name of your Storage batch operation job + # job_name = "your-job-name" require "google/cloud/storage_batch_operations/v1" @@ -49,11 +55,10 @@ def create_job bucket_name:, prefix:, job_name:, parent: delete_object: delete_object ) - request = Google::Cloud::StorageBatchOperations::V1::CreateJobRequest.new(parent: parent, job_id: job_name, job: job ) + request = Google::Cloud::StorageBatchOperations::V1::CreateJobRequest.new parent: parent, job_id: job_name, job: job result = client.create_job request puts result.is_a?(Gapic::Operation) ? "The job is created." : "The job is not created." - end # [END storage_batch_create_job] diff --git a/google-cloud-storage_batch_operations/samples/storage_batch_delete_job.rb b/google-cloud-storage_batch_operations/samples/storage_batch_delete_job.rb index bc40fabf0ebb..4b8e7694f8e2 100644 --- a/google-cloud-storage_batch_operations/samples/storage_batch_delete_job.rb +++ b/google-cloud-storage_batch_operations/samples/storage_batch_delete_job.rb @@ -26,7 +26,6 @@ def delete_job parent:, job_name: request = Google::Cloud::StorageBatchOperations::V1::DeleteJobRequest.new name: "#{parent}/jobs/#{job_name}" result = client.delete_job request puts result.is_a?(Google::Protobuf::Empty) ? "The job is deleted." : "The job is not deleted." - end # [END storage_batch_delete_job] diff --git a/google-cloud-storage_batch_operations/samples/storage_batch_get_job.rb b/google-cloud-storage_batch_operations/samples/storage_batch_get_job.rb index b01c453491ba..a13c58aa3abb 100644 --- a/google-cloud-storage_batch_operations/samples/storage_batch_get_job.rb +++ b/google-cloud-storage_batch_operations/samples/storage_batch_get_job.rb @@ -1,4 +1,3 @@ - # Copyright 2025 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/google-cloud-storage_batch_operations/samples/storage_batch_get_job_status.rb b/google-cloud-storage_batch_operations/samples/storage_batch_get_job_status.rb index 11d101a31a7b..7b942d0ad3dc 100644 --- a/google-cloud-storage_batch_operations/samples/storage_batch_get_job_status.rb +++ b/google-cloud-storage_batch_operations/samples/storage_batch_get_job_status.rb @@ -1,4 +1,3 @@ - # Copyright 2025 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/google-cloud-storage_batch_operations/samples/storage_batch_list_job.rb b/google-cloud-storage_batch_operations/samples/storage_batch_list_job.rb index 4c264a97aac9..a8e658de120a 100644 --- a/google-cloud-storage_batch_operations/samples/storage_batch_list_job.rb +++ b/google-cloud-storage_batch_operations/samples/storage_batch_list_job.rb @@ -25,7 +25,6 @@ def list_job parent: result.each do |job| puts "Job name: #{job.name}" end - end # [END storage_batch_list_job] From 3f173660e0c15c1c82e26cde14c437e202387310 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Wed, 11 Jun 2025 17:49:14 +0000 Subject: [PATCH 03/17] updating --- google-cloud-storage_batch_operations/samples/Gemfile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/google-cloud-storage_batch_operations/samples/Gemfile b/google-cloud-storage_batch_operations/samples/Gemfile index cc1abc83d299..a7dcd1ef2cc0 100644 --- a/google-cloud-storage_batch_operations/samples/Gemfile +++ b/google-cloud-storage_batch_operations/samples/Gemfile @@ -1,4 +1,4 @@ -# Copyright 2020 Google LLC +# Copyright 2025 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -36,4 +36,3 @@ group :test do gem "minitest-hooks", "~> 1.5" gem "rake" end -gem "yard" From 9851c7e4b9e07f81b5b96e19d276fbadd96a4053 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Wed, 11 Jun 2025 17:50:37 +0000 Subject: [PATCH 04/17] updating --- .../samples/acceptance/helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-storage_batch_operations/samples/acceptance/helper.rb b/google-cloud-storage_batch_operations/samples/acceptance/helper.rb index 7f86723c96cf..bf98969247e8 100644 --- a/google-cloud-storage_batch_operations/samples/acceptance/helper.rb +++ b/google-cloud-storage_batch_operations/samples/acceptance/helper.rb @@ -1,4 +1,4 @@ -# Copyright 2020 Google LLC +# Copyright 2025 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. From b274ae496c838fc4b31857cd60c3f6fa8b52f22f Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Thu, 12 Jun 2025 17:14:27 +0000 Subject: [PATCH 05/17] fixing test cases --- .../samples/Rakefile | 6 ++++ .../samples/acceptance/batch_job_test.rb | 21 ++++++------ .../samples/acceptance/helper.rb | 3 +- .../samples/storage_batch_cancel_job.rb | 5 +-- .../samples/storage_batch_create_job.rb | 5 +-- .../samples/storage_batch_delete_job.rb | 5 +-- .../samples/storage_batch_get_job.rb | 7 ++-- .../samples/storage_batch_get_job_status.rb | 32 ------------------- .../samples/storage_batch_list_job.rb | 6 ++-- 9 files changed, 33 insertions(+), 57 deletions(-) create mode 100644 google-cloud-storage_batch_operations/samples/Rakefile delete mode 100644 google-cloud-storage_batch_operations/samples/storage_batch_get_job_status.rb diff --git a/google-cloud-storage_batch_operations/samples/Rakefile b/google-cloud-storage_batch_operations/samples/Rakefile new file mode 100644 index 000000000000..6326eebd9945 --- /dev/null +++ b/google-cloud-storage_batch_operations/samples/Rakefile @@ -0,0 +1,6 @@ +require "rake/testtask" + +Rake::TestTask.new "test" do |t| + t.test_files = FileList["**/*_test.rb"] + t.warning = false +end diff --git a/google-cloud-storage_batch_operations/samples/acceptance/batch_job_test.rb b/google-cloud-storage_batch_operations/samples/acceptance/batch_job_test.rb index 19e2cfb53544..39dee3a50d29 100644 --- a/google-cloud-storage_batch_operations/samples/acceptance/batch_job_test.rb +++ b/google-cloud-storage_batch_operations/samples/acceptance/batch_job_test.rb @@ -12,7 +12,6 @@ describe "Batch jobs Snippets" do let(:storage_client) { Google::Cloud::Storage.new } let(:project_name) { storage_client.project } - let(:parent) { "projects/#{project_name}/locations/global" } let(:bucket) { @bucket } let(:file_content) { "some content" } let(:remote_file_name) { "ruby_file_#{SecureRandom.hex}" } @@ -29,7 +28,7 @@ def create_test_job my_job bucket.create_file StringIO.new(file_content), remote_file_name - create_job bucket_name: bucket.name, prefix: "ruby_file", job_name: my_job, parent: parent + create_job bucket_name: bucket.name, prefix: "ruby_file", job_name: my_job, project_name: project_name end describe "storage batch manage operations" do @@ -39,19 +38,19 @@ def create_test_job my_job end it "lists jobs and includes the created job" do - out, _err = capture_io { list_job parent: parent } + out, _err = capture_io { list_job project_name: project_name } assert_includes out, @job_name, "Expected job name not found in the result list" end it "fetches the details of a job" do - assert_output "#{parent}/jobs/#{job_name}\n" do - get_job parent: parent, job_name: job_name - end + result = get_job project_name: project_name, job_name: job_name + assert_includes result, @job_name, "Expected job name not found in the result" + end it "cancels a job" do assert_output "The job is canceled.\n" do - cancel_job parent: parent, job_name: job_name + cancel_job project_name: project_name, job_name: @job_name end end end @@ -63,19 +62,19 @@ def create_test_job my_job end it "deletes a job" do retry_job_status do - get_job_status parent: parent, job_name: job_name + get_job project_name: project_name, job_name: @job_name end assert_output "The job is deleted.\n" do - delete_job parent: parent, job_name: job_name + delete_job project_name: project_name, job_name: @job_name end end end describe "creates a storage batch ops" do it "creates a job" do - assert_output "The job is created.\n" do - @job_name = "ruby-sbo-job-#{SecureRandom.hex}" + @job_name = "ruby-sbo-job-#{SecureRandom.hex}" + assert_output "The job is created.\n" do create_test_job job_name end end diff --git a/google-cloud-storage_batch_operations/samples/acceptance/helper.rb b/google-cloud-storage_batch_operations/samples/acceptance/helper.rb index bf98969247e8..0ad64df5157a 100644 --- a/google-cloud-storage_batch_operations/samples/acceptance/helper.rb +++ b/google-cloud-storage_batch_operations/samples/acceptance/helper.rb @@ -24,7 +24,6 @@ require "uri" require "ostruct" - def create_bucket_helper bucket_name storage_client = Google::Cloud::Storage.new retry_resource_exhaustion do @@ -45,7 +44,7 @@ def delete_bucket_helper bucket_name def retry_job_status 5.times do - if yield == :RUNNING + if yield[/job_status-\s*(\w+)/, 1] == "RUNNING" puts "Job in Running status Gonna try again" sleep rand(5..9) end diff --git a/google-cloud-storage_batch_operations/samples/storage_batch_cancel_job.rb b/google-cloud-storage_batch_operations/samples/storage_batch_cancel_job.rb index 1e308d6e2b2d..8fda18cd9dbd 100644 --- a/google-cloud-storage_batch_operations/samples/storage_batch_cancel_job.rb +++ b/google-cloud-storage_batch_operations/samples/storage_batch_cancel_job.rb @@ -13,7 +13,7 @@ # limitations under the License. # [START storage_batch_cancel_job] -def cancel_job parent:, job_name: +def cancel_job project_name:, job_name: # The parent location for your job # parent = "projects/your-project-id/locations/your-location" @@ -23,6 +23,7 @@ def cancel_job parent:, job_name: require "google/cloud/storage_batch_operations/v1" client = Google::Cloud::StorageBatchOperations::V1::StorageBatchOperations::Client.new + parent = "projects/#{project_name}/locations/global" request = Google::Cloud::StorageBatchOperations::V1::CancelJobRequest.new name: "#{parent}/jobs/#{job_name}" result = client.cancel_job request @@ -30,4 +31,4 @@ def cancel_job parent:, job_name: end # [END storage_batch_cancel_job] -cancel_job parent: ARGV.shift, job_name: ARGV.shift if $PROGRAM_NAME == __FILE__ +cancel_job project_name: ARGV.shift, job_name: ARGV.shift if $PROGRAM_NAME == __FILE__ diff --git a/google-cloud-storage_batch_operations/samples/storage_batch_create_job.rb b/google-cloud-storage_batch_operations/samples/storage_batch_create_job.rb index 94c622ad3090..80d79d8549ea 100644 --- a/google-cloud-storage_batch_operations/samples/storage_batch_create_job.rb +++ b/google-cloud-storage_batch_operations/samples/storage_batch_create_job.rb @@ -13,7 +13,7 @@ # limitations under the License. # [START storage_batch_create_job] -def create_job bucket_name:, prefix:, job_name:, parent: +def create_job bucket_name:, prefix:, job_name:, project_name: # The ID of your GCS bucket # bucket_name = "your-unique-bucket-name" @@ -29,6 +29,7 @@ def create_job bucket_name:, prefix:, job_name:, parent: require "google/cloud/storage_batch_operations/v1" client = Google::Cloud::StorageBatchOperations::V1::StorageBatchOperations::Client.new + parent = "projects/#{project_name}/locations/global" prefix_list = Google::Cloud::StorageBatchOperations::V1::PrefixList.new( included_object_prefixes: [prefix] @@ -62,4 +63,4 @@ def create_job bucket_name:, prefix:, job_name:, parent: end # [END storage_batch_create_job] -create_job bucket_name: ARGV.shift, prefix: ARGV.shift, job_name: ARGV.shift, parent: ARGV.shift, job_type: ARGV.shift if $PROGRAM_NAME == __FILE__ +create_job bucket_name: ARGV.shift, prefix: ARGV.shift, job_name: ARGV.shift, project_name: ARGV.shift, job_type: ARGV.shift if $PROGRAM_NAME == __FILE__ diff --git a/google-cloud-storage_batch_operations/samples/storage_batch_delete_job.rb b/google-cloud-storage_batch_operations/samples/storage_batch_delete_job.rb index 4b8e7694f8e2..87f45214a7a1 100644 --- a/google-cloud-storage_batch_operations/samples/storage_batch_delete_job.rb +++ b/google-cloud-storage_batch_operations/samples/storage_batch_delete_job.rb @@ -13,7 +13,7 @@ # limitations under the License. # [START storage_batch_delete_job] -def delete_job parent:, job_name: +def delete_job project_name:, job_name: # The parent location for your job # parent = "projects/your-project-id/locations/your-location" @@ -23,10 +23,11 @@ def delete_job parent:, job_name: require "google/cloud/storage_batch_operations/v1" client = Google::Cloud::StorageBatchOperations::V1::StorageBatchOperations::Client.new + parent = "projects/#{project_name}/locations/global" request = Google::Cloud::StorageBatchOperations::V1::DeleteJobRequest.new name: "#{parent}/jobs/#{job_name}" result = client.delete_job request puts result.is_a?(Google::Protobuf::Empty) ? "The job is deleted." : "The job is not deleted." end # [END storage_batch_delete_job] -delete_job parent: ARGV.shift, job_name: ARGV.shift if $PROGRAM_NAME == __FILE__ +delete_job project_name: ARGV.shift, job_name: ARGV.shift if $PROGRAM_NAME == __FILE__ diff --git a/google-cloud-storage_batch_operations/samples/storage_batch_get_job.rb b/google-cloud-storage_batch_operations/samples/storage_batch_get_job.rb index a13c58aa3abb..c18e009b96c3 100644 --- a/google-cloud-storage_batch_operations/samples/storage_batch_get_job.rb +++ b/google-cloud-storage_batch_operations/samples/storage_batch_get_job.rb @@ -13,7 +13,7 @@ # limitations under the License. # [START storage_batch_get_job] -def get_job parent:, job_name: +def get_job project_name:, job_name: # The parent location for your job # parent = "projects/your-project-id/locations/your-location" @@ -23,10 +23,11 @@ def get_job parent:, job_name: require "google/cloud/storage_batch_operations/v1" client = Google::Cloud::StorageBatchOperations::V1::StorageBatchOperations::Client.new + parent = "projects/#{project_name}/locations/global" request = Google::Cloud::StorageBatchOperations::V1::GetJobRequest.new name: "#{parent}/jobs/#{job_name}" result = client.get_job request - puts result.name + return "job_name- #{result.name}, job_status- #{result.state}" end # [END storage_batch_get_job] -get_job parent: ARGV.shift, job_name: ARGV.shift if $PROGRAM_NAME == __FILE__ +get_job project_name: ARGV.shift, job_name: ARGV.shift if $PROGRAM_NAME == __FILE__ diff --git a/google-cloud-storage_batch_operations/samples/storage_batch_get_job_status.rb b/google-cloud-storage_batch_operations/samples/storage_batch_get_job_status.rb deleted file mode 100644 index 7b942d0ad3dc..000000000000 --- a/google-cloud-storage_batch_operations/samples/storage_batch_get_job_status.rb +++ /dev/null @@ -1,32 +0,0 @@ -# Copyright 2025 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# [START storage_batch_get_job_status] -def get_job_status parent:, job_name: - # The parent location for your job - # parent = "projects/your-project-id/locations/your-location" - - # The name of your Storage batch operation job - # job_name = "your-job-name" - - require "google/cloud/storage_batch_operations/v1" - - client = Google::Cloud::StorageBatchOperations::V1::StorageBatchOperations::Client.new - request = Google::Cloud::StorageBatchOperations::V1::GetJobRequest.new name: "#{parent}/jobs/#{job_name}" - result = client.get_job request - result.state -end -# [END storage_batch_get_job_status] - -get_job parent: ARGV.shift, job_name: ARGV.shift if $PROGRAM_NAME == __FILE__ diff --git a/google-cloud-storage_batch_operations/samples/storage_batch_list_job.rb b/google-cloud-storage_batch_operations/samples/storage_batch_list_job.rb index a8e658de120a..f6423e4557d5 100644 --- a/google-cloud-storage_batch_operations/samples/storage_batch_list_job.rb +++ b/google-cloud-storage_batch_operations/samples/storage_batch_list_job.rb @@ -13,13 +13,13 @@ # limitations under the License. # [START storage_batch_list_job] -def list_job parent: +def list_job project_name: # The parent location for your job # parent = "projects/your-project-id/locations/your-location" require "google/cloud/storage_batch_operations/v1" client = Google::Cloud::StorageBatchOperations::V1::StorageBatchOperations::Client.new - + parent = "projects/#{project_name}/locations/global" request = Google::Cloud::StorageBatchOperations::V1::ListJobsRequest.new parent: parent, page_size: 10 result = client.list_jobs request result.each do |job| @@ -28,4 +28,4 @@ def list_job parent: end # [END storage_batch_list_job] -delete_job parent: ARGV.shift, job_name: ARGV.shift if $PROGRAM_NAME == __FILE__ +delete_job project_name: ARGV.shift, job_name: ARGV.shift if $PROGRAM_NAME == __FILE__ From a38fca454af18ea38f5945010d77958010b48699 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Fri, 13 Jun 2025 04:16:24 +0000 Subject: [PATCH 06/17] fix test cases --- .../samples/.rubocop.yml | 24 +++++++++++++++++++ .../samples/Gemfile | 1 + .../samples/acceptance/batch_job_test.rb | 4 +--- .../samples/storage_batch_cancel_job.rb | 7 +++++- .../samples/storage_batch_create_job.rb | 10 +++++++- .../samples/storage_batch_get_job.rb | 2 +- 6 files changed, 42 insertions(+), 6 deletions(-) create mode 100644 google-cloud-storage_batch_operations/samples/.rubocop.yml diff --git a/google-cloud-storage_batch_operations/samples/.rubocop.yml b/google-cloud-storage_batch_operations/samples/.rubocop.yml new file mode 100644 index 000000000000..b3a280358647 --- /dev/null +++ b/google-cloud-storage_batch_operations/samples/.rubocop.yml @@ -0,0 +1,24 @@ +inherit_gem: + google-style: google-style.yml + +Lint/EmptyBlock: + Enabled: false +Lint/ShadowingOuterLocalVariable: + Enabled: false +Metrics/AbcSize: + Enabled: false +Metrics/BlockLength: + Enabled: false +Metrics/CyclomaticComplexity: + Max: 12 +Metrics/MethodLength: + Enabled: false +Naming/AccessorMethodName: + Enabled: false +Style/GlobalVars: + Exclude: + - "acceptance/helper.rb" +Style/Next: + Enabled: false +Style/SymbolProc: + Enabled: false diff --git a/google-cloud-storage_batch_operations/samples/Gemfile b/google-cloud-storage_batch_operations/samples/Gemfile index a7dcd1ef2cc0..97406e26c5e8 100644 --- a/google-cloud-storage_batch_operations/samples/Gemfile +++ b/google-cloud-storage_batch_operations/samples/Gemfile @@ -29,6 +29,7 @@ else # [END storage_dependencies] end +gem "yard" group :test do gem "google-style", "~> 1.30.0" gem "minitest", "~> 5.14" diff --git a/google-cloud-storage_batch_operations/samples/acceptance/batch_job_test.rb b/google-cloud-storage_batch_operations/samples/acceptance/batch_job_test.rb index 39dee3a50d29..2ee21e1cbd9f 100644 --- a/google-cloud-storage_batch_operations/samples/acceptance/batch_job_test.rb +++ b/google-cloud-storage_batch_operations/samples/acceptance/batch_job_test.rb @@ -7,7 +7,6 @@ require_relative "../storage_batch_cancel_job" require_relative "../storage_batch_list_job" require_relative "../storage_batch_get_job" -require_relative "../storage_batch_get_job_status" describe "Batch jobs Snippets" do let(:storage_client) { Google::Cloud::Storage.new } @@ -43,9 +42,8 @@ def create_test_job my_job end it "fetches the details of a job" do - result = get_job project_name: project_name, job_name: job_name + result = get_job project_name: project_name, job_name: job_name assert_includes result, @job_name, "Expected job name not found in the result" - end it "cancels a job" do diff --git a/google-cloud-storage_batch_operations/samples/storage_batch_cancel_job.rb b/google-cloud-storage_batch_operations/samples/storage_batch_cancel_job.rb index 8fda18cd9dbd..92abfa52d956 100644 --- a/google-cloud-storage_batch_operations/samples/storage_batch_cancel_job.rb +++ b/google-cloud-storage_batch_operations/samples/storage_batch_cancel_job.rb @@ -27,7 +27,12 @@ def cancel_job project_name:, job_name: request = Google::Cloud::StorageBatchOperations::V1::CancelJobRequest.new name: "#{parent}/jobs/#{job_name}" result = client.cancel_job request - puts result.is_a?(Google::Cloud::StorageBatchOperations::V1::CancelJobResponse) ? "The job is canceled." : "The job is not canceled." + message = if result.is_a? Google::Cloud::StorageBatchOperations::V1::CancelJobResponse + "The job is canceled." + else + "The job is not canceled." + end + puts message end # [END storage_batch_cancel_job] diff --git a/google-cloud-storage_batch_operations/samples/storage_batch_create_job.rb b/google-cloud-storage_batch_operations/samples/storage_batch_create_job.rb index 80d79d8549ea..0537a6029586 100644 --- a/google-cloud-storage_batch_operations/samples/storage_batch_create_job.rb +++ b/google-cloud-storage_batch_operations/samples/storage_batch_create_job.rb @@ -63,4 +63,12 @@ def create_job bucket_name:, prefix:, job_name:, project_name: end # [END storage_batch_create_job] -create_job bucket_name: ARGV.shift, prefix: ARGV.shift, job_name: ARGV.shift, project_name: ARGV.shift, job_type: ARGV.shift if $PROGRAM_NAME == __FILE__ +if $PROGRAM_NAME == __FILE__ + create_job( + bucket_name: ARGV.shift, + prefix: ARGV.shift, + job_name: ARGV.shift, + project_name: ARGV.shift, + job_type: ARGV.shift + ) +end diff --git a/google-cloud-storage_batch_operations/samples/storage_batch_get_job.rb b/google-cloud-storage_batch_operations/samples/storage_batch_get_job.rb index c18e009b96c3..5131a0b244a9 100644 --- a/google-cloud-storage_batch_operations/samples/storage_batch_get_job.rb +++ b/google-cloud-storage_batch_operations/samples/storage_batch_get_job.rb @@ -26,7 +26,7 @@ def get_job project_name:, job_name: parent = "projects/#{project_name}/locations/global" request = Google::Cloud::StorageBatchOperations::V1::GetJobRequest.new name: "#{parent}/jobs/#{job_name}" result = client.get_job request - return "job_name- #{result.name}, job_status- #{result.state}" + "job_name- #{result.name}, job_status- #{result.state}" end # [END storage_batch_get_job] From 474d7e232cd4772801bf9ebc49da743448fec5da Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Fri, 13 Jun 2025 07:47:40 +0000 Subject: [PATCH 07/17] fix comments --- .../samples/acceptance/batch_job_test.rb | 10 +++++----- .../samples/storage_batch_cancel_job.rb | 8 ++++---- .../samples/storage_batch_create_job.rb | 6 +++--- .../samples/storage_batch_delete_job.rb | 6 +++--- .../samples/storage_batch_get_job.rb | 4 ++-- .../samples/storage_batch_list_job.rb | 4 ++-- 6 files changed, 19 insertions(+), 19 deletions(-) diff --git a/google-cloud-storage_batch_operations/samples/acceptance/batch_job_test.rb b/google-cloud-storage_batch_operations/samples/acceptance/batch_job_test.rb index 2ee21e1cbd9f..2a6a2812ac2b 100644 --- a/google-cloud-storage_batch_operations/samples/acceptance/batch_job_test.rb +++ b/google-cloud-storage_batch_operations/samples/acceptance/batch_job_test.rb @@ -47,13 +47,13 @@ def create_test_job my_job end it "cancels a job" do - assert_output "The job is canceled.\n" do + assert_output "The #{@job_name} is canceled.\n" do cancel_job project_name: project_name, job_name: @job_name end end end - describe "Delete storage batch ops" do + describe "Delete storage batch operation" do before do @job_name = "ruby-sbo-job-#{SecureRandom.hex}" create_test_job job_name @@ -62,17 +62,17 @@ def create_test_job my_job retry_job_status do get_job project_name: project_name, job_name: @job_name end - assert_output "The job is deleted.\n" do + assert_output "The #{@job_name} is deleted.\n" do delete_job project_name: project_name, job_name: @job_name end end end - describe "creates a storage batch ops" do + describe "creates a storage batch operation" do it "creates a job" do @job_name = "ruby-sbo-job-#{SecureRandom.hex}" - assert_output "The job is created.\n" do + assert_output "The #{@job_name} is created.\n" do create_test_job job_name end end diff --git a/google-cloud-storage_batch_operations/samples/storage_batch_cancel_job.rb b/google-cloud-storage_batch_operations/samples/storage_batch_cancel_job.rb index 92abfa52d956..2e334b4ecc2c 100644 --- a/google-cloud-storage_batch_operations/samples/storage_batch_cancel_job.rb +++ b/google-cloud-storage_batch_operations/samples/storage_batch_cancel_job.rb @@ -14,8 +14,8 @@ # [START storage_batch_cancel_job] def cancel_job project_name:, job_name: - # The parent location for your job - # parent = "projects/your-project-id/locations/your-location" + # The Name/ID of your project + # project_name = "your-project-id" # The name of your Storage batch operation job # job_name = "your-job-name" @@ -28,9 +28,9 @@ def cancel_job project_name:, job_name: request = Google::Cloud::StorageBatchOperations::V1::CancelJobRequest.new name: "#{parent}/jobs/#{job_name}" result = client.cancel_job request message = if result.is_a? Google::Cloud::StorageBatchOperations::V1::CancelJobResponse - "The job is canceled." + "The #{job_name} is canceled." else - "The job is not canceled." + "The #{job_name} is not canceled." end puts message end diff --git a/google-cloud-storage_batch_operations/samples/storage_batch_create_job.rb b/google-cloud-storage_batch_operations/samples/storage_batch_create_job.rb index 0537a6029586..8d930e84de11 100644 --- a/google-cloud-storage_batch_operations/samples/storage_batch_create_job.rb +++ b/google-cloud-storage_batch_operations/samples/storage_batch_create_job.rb @@ -20,8 +20,8 @@ def create_job bucket_name:, prefix:, job_name:, project_name: # Prefix is the first part of filename on which job has to be executed # prefix = 'test' - # The parent location for your job - # parent = "projects/your-project-id/locations/your-location" + # The Name/ID of your project + # project_name = "your-project-id" # The name of your Storage batch operation job # job_name = "your-job-name" @@ -59,7 +59,7 @@ def create_job bucket_name:, prefix:, job_name:, project_name: request = Google::Cloud::StorageBatchOperations::V1::CreateJobRequest.new parent: parent, job_id: job_name, job: job result = client.create_job request - puts result.is_a?(Gapic::Operation) ? "The job is created." : "The job is not created." + puts result.is_a?(Gapic::Operation) ? "The #{job_name} is created." : "The #{job_name} is not created." end # [END storage_batch_create_job] diff --git a/google-cloud-storage_batch_operations/samples/storage_batch_delete_job.rb b/google-cloud-storage_batch_operations/samples/storage_batch_delete_job.rb index 87f45214a7a1..094067d16e98 100644 --- a/google-cloud-storage_batch_operations/samples/storage_batch_delete_job.rb +++ b/google-cloud-storage_batch_operations/samples/storage_batch_delete_job.rb @@ -14,8 +14,8 @@ # [START storage_batch_delete_job] def delete_job project_name:, job_name: - # The parent location for your job - # parent = "projects/your-project-id/locations/your-location" + # The Name/ID of your project + # project_name = "your-project-id" # The name of your Storage batch operation job # job_name = "your-job-name" @@ -26,7 +26,7 @@ def delete_job project_name:, job_name: parent = "projects/#{project_name}/locations/global" request = Google::Cloud::StorageBatchOperations::V1::DeleteJobRequest.new name: "#{parent}/jobs/#{job_name}" result = client.delete_job request - puts result.is_a?(Google::Protobuf::Empty) ? "The job is deleted." : "The job is not deleted." + puts result.is_a?(Google::Protobuf::Empty) ? "The #{job_name} is deleted." : "The #{job_name} is not deleted." end # [END storage_batch_delete_job] diff --git a/google-cloud-storage_batch_operations/samples/storage_batch_get_job.rb b/google-cloud-storage_batch_operations/samples/storage_batch_get_job.rb index 5131a0b244a9..0f3bb7ecbc43 100644 --- a/google-cloud-storage_batch_operations/samples/storage_batch_get_job.rb +++ b/google-cloud-storage_batch_operations/samples/storage_batch_get_job.rb @@ -14,8 +14,8 @@ # [START storage_batch_get_job] def get_job project_name:, job_name: - # The parent location for your job - # parent = "projects/your-project-id/locations/your-location" + # The Name/ID of your project + # project_name = "your-project-id" # The name of your Storage batch operation job # job_name = "your-job-name" diff --git a/google-cloud-storage_batch_operations/samples/storage_batch_list_job.rb b/google-cloud-storage_batch_operations/samples/storage_batch_list_job.rb index f6423e4557d5..fbed1c280acd 100644 --- a/google-cloud-storage_batch_operations/samples/storage_batch_list_job.rb +++ b/google-cloud-storage_batch_operations/samples/storage_batch_list_job.rb @@ -14,8 +14,8 @@ # [START storage_batch_list_job] def list_job project_name: - # The parent location for your job - # parent = "projects/your-project-id/locations/your-location" + # The Name/ID of your project + # project_name = "your-project-id" require "google/cloud/storage_batch_operations/v1" client = Google::Cloud::StorageBatchOperations::V1::StorageBatchOperations::Client.new From 9821e4f8acbcb0391a735e1ea18d043f9acff2d4 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Fri, 13 Jun 2025 09:16:29 +0000 Subject: [PATCH 08/17] fix test --- .../samples/acceptance/batch_job_test.rb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/google-cloud-storage_batch_operations/samples/acceptance/batch_job_test.rb b/google-cloud-storage_batch_operations/samples/acceptance/batch_job_test.rb index 2a6a2812ac2b..355518b85ef7 100644 --- a/google-cloud-storage_batch_operations/samples/acceptance/batch_job_test.rb +++ b/google-cloud-storage_batch_operations/samples/acceptance/batch_job_test.rb @@ -14,7 +14,6 @@ let(:bucket) { @bucket } let(:file_content) { "some content" } let(:remote_file_name) { "ruby_file_#{SecureRandom.hex}" } - let(:job_name) { @job_name } before :all do @@ -33,7 +32,7 @@ def create_test_job my_job describe "storage batch manage operations" do before do @job_name = "ruby-sbo-job-#{SecureRandom.hex}" - create_test_job job_name + create_test_job @job_name end it "lists jobs and includes the created job" do @@ -42,7 +41,7 @@ def create_test_job my_job end it "fetches the details of a job" do - result = get_job project_name: project_name, job_name: job_name + result = get_job project_name: project_name, job_name: @job_name assert_includes result, @job_name, "Expected job name not found in the result" end @@ -56,7 +55,7 @@ def create_test_job my_job describe "Delete storage batch operation" do before do @job_name = "ruby-sbo-job-#{SecureRandom.hex}" - create_test_job job_name + create_test_job @job_name end it "deletes a job" do retry_job_status do @@ -73,7 +72,7 @@ def create_test_job my_job @job_name = "ruby-sbo-job-#{SecureRandom.hex}" assert_output "The #{@job_name} is created.\n" do - create_test_job job_name + create_test_job @job_name end end end From c86088c848b4b112640e1af6e6b53967503a01c5 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Thu, 19 Jun 2025 16:16:51 +0530 Subject: [PATCH 09/17] Update Gemfile --- google-cloud-storage_batch_operations/samples/Gemfile | 1 - 1 file changed, 1 deletion(-) diff --git a/google-cloud-storage_batch_operations/samples/Gemfile b/google-cloud-storage_batch_operations/samples/Gemfile index 97406e26c5e8..1e40cd4830ec 100644 --- a/google-cloud-storage_batch_operations/samples/Gemfile +++ b/google-cloud-storage_batch_operations/samples/Gemfile @@ -28,7 +28,6 @@ else gem "google-cloud-storage_batch_operations" # [END storage_dependencies] end - gem "yard" group :test do gem "google-style", "~> 1.30.0" From e2b297f47c3295632b83e1f5ef15032983fe174e Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Fri, 20 Jun 2025 16:33:45 +0530 Subject: [PATCH 10/17] Update batch_job_test.rb --- .../samples/acceptance/batch_job_test.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/google-cloud-storage_batch_operations/samples/acceptance/batch_job_test.rb b/google-cloud-storage_batch_operations/samples/acceptance/batch_job_test.rb index 355518b85ef7..dac746b1e4de 100644 --- a/google-cloud-storage_batch_operations/samples/acceptance/batch_job_test.rb +++ b/google-cloud-storage_batch_operations/samples/acceptance/batch_job_test.rb @@ -15,7 +15,6 @@ let(:file_content) { "some content" } let(:remote_file_name) { "ruby_file_#{SecureRandom.hex}" } - before :all do @bucket = create_bucket_helper random_bucket_name end From 19009a89d8045a5274fe880bf52605d606aabcd7 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Fri, 20 Jun 2025 17:08:29 +0530 Subject: [PATCH 11/17] Update batch_job_test.rb --- .../samples/acceptance/batch_job_test.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/google-cloud-storage_batch_operations/samples/acceptance/batch_job_test.rb b/google-cloud-storage_batch_operations/samples/acceptance/batch_job_test.rb index dac746b1e4de..f24cf2cdc6ad 100644 --- a/google-cloud-storage_batch_operations/samples/acceptance/batch_job_test.rb +++ b/google-cloud-storage_batch_operations/samples/acceptance/batch_job_test.rb @@ -69,7 +69,6 @@ def create_test_job my_job describe "creates a storage batch operation" do it "creates a job" do @job_name = "ruby-sbo-job-#{SecureRandom.hex}" - assert_output "The #{@job_name} is created.\n" do create_test_job @job_name end From e626edbbdd4b69559170f9901391730af8c51471 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Mon, 23 Jun 2025 12:52:25 +0530 Subject: [PATCH 12/17] Update helper.rb --- .../samples/acceptance/helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-storage_batch_operations/samples/acceptance/helper.rb b/google-cloud-storage_batch_operations/samples/acceptance/helper.rb index 0ad64df5157a..8dbe6ae5672f 100644 --- a/google-cloud-storage_batch_operations/samples/acceptance/helper.rb +++ b/google-cloud-storage_batch_operations/samples/acceptance/helper.rb @@ -46,7 +46,7 @@ def retry_job_status 5.times do if yield[/job_status-\s*(\w+)/, 1] == "RUNNING" puts "Job in Running status Gonna try again" - sleep rand(5..9) + sleep rand(10..16) end end end From fcb8310f5b3ccc057e2aad1a14c238db71e649e7 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Tue, 1 Jul 2025 17:18:15 +0000 Subject: [PATCH 13/17] adding full License --- .../samples/Gemfile | 7 ------- .../samples/Rakefile | 14 ++++++++++++++ .../samples/acceptance/batch_job_test.rb | 13 ++++++++++++- .../samples/acceptance/helper.rb | 3 --- 4 files changed, 26 insertions(+), 11 deletions(-) diff --git a/google-cloud-storage_batch_operations/samples/Gemfile b/google-cloud-storage_batch_operations/samples/Gemfile index 1e40cd4830ec..7bef6bb8625f 100644 --- a/google-cloud-storage_batch_operations/samples/Gemfile +++ b/google-cloud-storage_batch_operations/samples/Gemfile @@ -12,21 +12,14 @@ # See the License for the specific language governing permissions and # limitations under the License. -# [START storage_dependencies] source "https://rubygems.org" -# [END storage_dependencies] - if ENV["GOOGLE_CLOUD_SAMPLES_TEST"] == "master" - gem "google-cloud-kms", group: :test, path: "../../google-cloud-kms" gem "google-cloud-storage", path: "../../google-cloud-storage" gem "google-cloud-storage_batch_operations", path: "../../google-cloud-storage_batch_operations" else - # [START storage_dependencies] - gem "google-cloud-kms" gem "google-cloud-storage" gem "google-cloud-storage_batch_operations" - # [END storage_dependencies] end gem "yard" group :test do diff --git a/google-cloud-storage_batch_operations/samples/Rakefile b/google-cloud-storage_batch_operations/samples/Rakefile index 6326eebd9945..fae40276bdec 100644 --- a/google-cloud-storage_batch_operations/samples/Rakefile +++ b/google-cloud-storage_batch_operations/samples/Rakefile @@ -1,3 +1,17 @@ +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + require "rake/testtask" Rake::TestTask.new "test" do |t| diff --git a/google-cloud-storage_batch_operations/samples/acceptance/batch_job_test.rb b/google-cloud-storage_batch_operations/samples/acceptance/batch_job_test.rb index f24cf2cdc6ad..7579337383d8 100644 --- a/google-cloud-storage_batch_operations/samples/acceptance/batch_job_test.rb +++ b/google-cloud-storage_batch_operations/samples/acceptance/batch_job_test.rb @@ -1,5 +1,16 @@ # Copyright 2025 Google LLC -# Licensed under the Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. require_relative "helper" require_relative "../storage_batch_create_job" diff --git a/google-cloud-storage_batch_operations/samples/acceptance/helper.rb b/google-cloud-storage_batch_operations/samples/acceptance/helper.rb index 8dbe6ae5672f..91530a16aa52 100644 --- a/google-cloud-storage_batch_operations/samples/acceptance/helper.rb +++ b/google-cloud-storage_batch_operations/samples/acceptance/helper.rb @@ -13,7 +13,6 @@ # limitations under the License. require "google/cloud/errors" -require "google/cloud/kms" require "google/cloud/storage" require "minitest/autorun" require "minitest/focus" @@ -21,8 +20,6 @@ require "net/http" require "time" require "securerandom" -require "uri" -require "ostruct" def create_bucket_helper bucket_name storage_client = Google::Cloud::Storage.new From 5eddc250cbf1ee426ff25dd93ade975ab8bdab01 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Tue, 1 Jul 2025 17:31:14 +0000 Subject: [PATCH 14/17] fixing lint --- google-cloud-storage_batch_operations/samples/Gemfile | 1 - .../samples/acceptance/batch_job_test.rb | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/google-cloud-storage_batch_operations/samples/Gemfile b/google-cloud-storage_batch_operations/samples/Gemfile index 7bef6bb8625f..c0c86bd60ee2 100644 --- a/google-cloud-storage_batch_operations/samples/Gemfile +++ b/google-cloud-storage_batch_operations/samples/Gemfile @@ -21,7 +21,6 @@ else gem "google-cloud-storage" gem "google-cloud-storage_batch_operations" end -gem "yard" group :test do gem "google-style", "~> 1.30.0" gem "minitest", "~> 5.14" diff --git a/google-cloud-storage_batch_operations/samples/acceptance/batch_job_test.rb b/google-cloud-storage_batch_operations/samples/acceptance/batch_job_test.rb index 7579337383d8..6cefa25ff30a 100644 --- a/google-cloud-storage_batch_operations/samples/acceptance/batch_job_test.rb +++ b/google-cloud-storage_batch_operations/samples/acceptance/batch_job_test.rb @@ -20,8 +20,7 @@ require_relative "../storage_batch_get_job" describe "Batch jobs Snippets" do - let(:storage_client) { Google::Cloud::Storage.new } - let(:project_name) { storage_client.project } + let(:project_name) { ENV['GCLOUD_TEST_PROJECT']} let(:bucket) { @bucket } let(:file_content) { "some content" } let(:remote_file_name) { "ruby_file_#{SecureRandom.hex}" } From 60cb50d5156cbaa0feec86e89a658ad9d3473162 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Tue, 1 Jul 2025 17:36:00 +0000 Subject: [PATCH 15/17] fixing lint --- .../samples/acceptance/batch_job_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-storage_batch_operations/samples/acceptance/batch_job_test.rb b/google-cloud-storage_batch_operations/samples/acceptance/batch_job_test.rb index 6cefa25ff30a..e4141a63c02e 100644 --- a/google-cloud-storage_batch_operations/samples/acceptance/batch_job_test.rb +++ b/google-cloud-storage_batch_operations/samples/acceptance/batch_job_test.rb @@ -20,7 +20,7 @@ require_relative "../storage_batch_get_job" describe "Batch jobs Snippets" do - let(:project_name) { ENV['GCLOUD_TEST_PROJECT']} + let(:project_name) { ENV["GCLOUD_TEST_PROJECT"] } let(:bucket) { @bucket } let(:file_content) { "some content" } let(:remote_file_name) { "ruby_file_#{SecureRandom.hex}" } From 3289696b45bec23b4ed2233e87c44118602755dd Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Tue, 22 Jul 2025 12:05:59 +0000 Subject: [PATCH 16/17] using wrapper class --- google-cloud-storage_batch_operations/samples/Gemfile | 4 ++-- .../samples/acceptance/helper.rb | 2 +- .../samples/storage_batch_cancel_job.rb | 5 ++--- .../samples/storage_batch_create_job.rb | 4 ++-- .../samples/storage_batch_delete_job.rb | 5 ++--- .../samples/storage_batch_get_job.rb | 5 +++-- .../samples/storage_batch_list_job.rb | 5 ++--- 7 files changed, 14 insertions(+), 16 deletions(-) diff --git a/google-cloud-storage_batch_operations/samples/Gemfile b/google-cloud-storage_batch_operations/samples/Gemfile index c0c86bd60ee2..c8bf8442a31b 100644 --- a/google-cloud-storage_batch_operations/samples/Gemfile +++ b/google-cloud-storage_batch_operations/samples/Gemfile @@ -15,8 +15,8 @@ source "https://rubygems.org" if ENV["GOOGLE_CLOUD_SAMPLES_TEST"] == "master" - gem "google-cloud-storage", path: "../../google-cloud-storage" - gem "google-cloud-storage_batch_operations", path: "../../google-cloud-storage_batch_operations" + gem "google-cloud-storage", group: :test, path: "../../google-cloud-storage" + gem "google-cloud-storage_batch_operations", group: :test, path: "../../google-cloud-storage_batch_operations" else gem "google-cloud-storage" gem "google-cloud-storage_batch_operations" diff --git a/google-cloud-storage_batch_operations/samples/acceptance/helper.rb b/google-cloud-storage_batch_operations/samples/acceptance/helper.rb index 91530a16aa52..e31f59af6e20 100644 --- a/google-cloud-storage_batch_operations/samples/acceptance/helper.rb +++ b/google-cloud-storage_batch_operations/samples/acceptance/helper.rb @@ -42,7 +42,7 @@ def delete_bucket_helper bucket_name def retry_job_status 5.times do if yield[/job_status-\s*(\w+)/, 1] == "RUNNING" - puts "Job in Running status Gonna try again" + puts "Job in Running status. Gonna try again" sleep rand(10..16) end end diff --git a/google-cloud-storage_batch_operations/samples/storage_batch_cancel_job.rb b/google-cloud-storage_batch_operations/samples/storage_batch_cancel_job.rb index 2e334b4ecc2c..6d097edb21d1 100644 --- a/google-cloud-storage_batch_operations/samples/storage_batch_cancel_job.rb +++ b/google-cloud-storage_batch_operations/samples/storage_batch_cancel_job.rb @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +require "google/cloud/storage_batch_operations" # [START storage_batch_cancel_job] def cancel_job project_name:, job_name: @@ -20,9 +21,7 @@ def cancel_job project_name:, job_name: # The name of your Storage batch operation job # job_name = "your-job-name" - require "google/cloud/storage_batch_operations/v1" - - client = Google::Cloud::StorageBatchOperations::V1::StorageBatchOperations::Client.new + client = Google::Cloud::StorageBatchOperations.storage_batch_operations parent = "projects/#{project_name}/locations/global" request = Google::Cloud::StorageBatchOperations::V1::CancelJobRequest.new name: "#{parent}/jobs/#{job_name}" diff --git a/google-cloud-storage_batch_operations/samples/storage_batch_create_job.rb b/google-cloud-storage_batch_operations/samples/storage_batch_create_job.rb index 8d930e84de11..271f98a37c0a 100644 --- a/google-cloud-storage_batch_operations/samples/storage_batch_create_job.rb +++ b/google-cloud-storage_batch_operations/samples/storage_batch_create_job.rb @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +require "google/cloud/storage_batch_operations" # [START storage_batch_create_job] def create_job bucket_name:, prefix:, job_name:, project_name: @@ -26,9 +27,8 @@ def create_job bucket_name:, prefix:, job_name:, project_name: # The name of your Storage batch operation job # job_name = "your-job-name" - require "google/cloud/storage_batch_operations/v1" + client = Google::Cloud::StorageBatchOperations.storage_batch_operations - client = Google::Cloud::StorageBatchOperations::V1::StorageBatchOperations::Client.new parent = "projects/#{project_name}/locations/global" prefix_list = Google::Cloud::StorageBatchOperations::V1::PrefixList.new( diff --git a/google-cloud-storage_batch_operations/samples/storage_batch_delete_job.rb b/google-cloud-storage_batch_operations/samples/storage_batch_delete_job.rb index 094067d16e98..8c0908930b4b 100644 --- a/google-cloud-storage_batch_operations/samples/storage_batch_delete_job.rb +++ b/google-cloud-storage_batch_operations/samples/storage_batch_delete_job.rb @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +require "google/cloud/storage_batch_operations" # [START storage_batch_delete_job] def delete_job project_name:, job_name: @@ -20,9 +21,7 @@ def delete_job project_name:, job_name: # The name of your Storage batch operation job # job_name = "your-job-name" - require "google/cloud/storage_batch_operations/v1" - - client = Google::Cloud::StorageBatchOperations::V1::StorageBatchOperations::Client.new + client = Google::Cloud::StorageBatchOperations.storage_batch_operations parent = "projects/#{project_name}/locations/global" request = Google::Cloud::StorageBatchOperations::V1::DeleteJobRequest.new name: "#{parent}/jobs/#{job_name}" result = client.delete_job request diff --git a/google-cloud-storage_batch_operations/samples/storage_batch_get_job.rb b/google-cloud-storage_batch_operations/samples/storage_batch_get_job.rb index 0f3bb7ecbc43..fce4b7e56524 100644 --- a/google-cloud-storage_batch_operations/samples/storage_batch_get_job.rb +++ b/google-cloud-storage_batch_operations/samples/storage_batch_get_job.rb @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +require "google/cloud/storage_batch_operations" # [START storage_batch_get_job] def get_job project_name:, job_name: @@ -20,9 +21,9 @@ def get_job project_name:, job_name: # The name of your Storage batch operation job # job_name = "your-job-name" - require "google/cloud/storage_batch_operations/v1" + require "google/cloud/storage_batch_operations" - client = Google::Cloud::StorageBatchOperations::V1::StorageBatchOperations::Client.new + client = Google::Cloud::StorageBatchOperations.storage_batch_operations parent = "projects/#{project_name}/locations/global" request = Google::Cloud::StorageBatchOperations::V1::GetJobRequest.new name: "#{parent}/jobs/#{job_name}" result = client.get_job request diff --git a/google-cloud-storage_batch_operations/samples/storage_batch_list_job.rb b/google-cloud-storage_batch_operations/samples/storage_batch_list_job.rb index fbed1c280acd..6a4316eb5c17 100644 --- a/google-cloud-storage_batch_operations/samples/storage_batch_list_job.rb +++ b/google-cloud-storage_batch_operations/samples/storage_batch_list_job.rb @@ -11,14 +11,13 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +require "google/cloud/storage_batch_operations" # [START storage_batch_list_job] def list_job project_name: # The Name/ID of your project # project_name = "your-project-id" - - require "google/cloud/storage_batch_operations/v1" - client = Google::Cloud::StorageBatchOperations::V1::StorageBatchOperations::Client.new + client = Google::Cloud::StorageBatchOperations.storage_batch_operations parent = "projects/#{project_name}/locations/global" request = Google::Cloud::StorageBatchOperations::V1::ListJobsRequest.new parent: parent, page_size: 10 result = client.list_jobs request From 2c2f3651b9dd12f76247562371aa5c011a4f36a1 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Tue, 26 Aug 2025 04:35:48 +0000 Subject: [PATCH 17/17] refactoring --- .../samples/acceptance/batch_job_test.rb | 5 ++++- .../samples/acceptance/helper.rb | 9 +++++---- .../samples/storage_batch_create_job.rb | 4 +--- .../samples/storage_batch_get_job.rb | 1 - .../samples/storage_batch_list_job.rb | 2 +- 5 files changed, 11 insertions(+), 10 deletions(-) diff --git a/google-cloud-storage_batch_operations/samples/acceptance/batch_job_test.rb b/google-cloud-storage_batch_operations/samples/acceptance/batch_job_test.rb index e4141a63c02e..5645295499a6 100644 --- a/google-cloud-storage_batch_operations/samples/acceptance/batch_job_test.rb +++ b/google-cloud-storage_batch_operations/samples/acceptance/batch_job_test.rb @@ -13,14 +13,17 @@ # limitations under the License. require_relative "helper" +require "google/cloud/storage" require_relative "../storage_batch_create_job" require_relative "../storage_batch_delete_job" require_relative "../storage_batch_cancel_job" require_relative "../storage_batch_list_job" require_relative "../storage_batch_get_job" +require 'pry' describe "Batch jobs Snippets" do - let(:project_name) { ENV["GCLOUD_TEST_PROJECT"] } + let(:storage) { Google::Cloud::Storage.new} + let(:project_name) { storage.project } let(:bucket) { @bucket } let(:file_content) { "some content" } let(:remote_file_name) { "ruby_file_#{SecureRandom.hex}" } diff --git a/google-cloud-storage_batch_operations/samples/acceptance/helper.rb b/google-cloud-storage_batch_operations/samples/acceptance/helper.rb index e31f59af6e20..2e5b28157562 100644 --- a/google-cloud-storage_batch_operations/samples/acceptance/helper.rb +++ b/google-cloud-storage_batch_operations/samples/acceptance/helper.rb @@ -41,10 +41,11 @@ def delete_bucket_helper bucket_name def retry_job_status 5.times do - if yield[/job_status-\s*(\w+)/, 1] == "RUNNING" - puts "Job in Running status. Gonna try again" - sleep rand(10..16) - end + status = yield[/job_status-\s*(\w+)/, 1] + break unless status == "RUNNING" + + puts "Job in Running status. Gonna try again" + sleep rand(10..16) end end diff --git a/google-cloud-storage_batch_operations/samples/storage_batch_create_job.rb b/google-cloud-storage_batch_operations/samples/storage_batch_create_job.rb index 271f98a37c0a..2a29bd58ac81 100644 --- a/google-cloud-storage_batch_operations/samples/storage_batch_create_job.rb +++ b/google-cloud-storage_batch_operations/samples/storage_batch_create_job.rb @@ -68,7 +68,5 @@ def create_job bucket_name:, prefix:, job_name:, project_name: bucket_name: ARGV.shift, prefix: ARGV.shift, job_name: ARGV.shift, - project_name: ARGV.shift, - job_type: ARGV.shift - ) + project_name: ARGV.shift ) end diff --git a/google-cloud-storage_batch_operations/samples/storage_batch_get_job.rb b/google-cloud-storage_batch_operations/samples/storage_batch_get_job.rb index fce4b7e56524..1d92e8e8cad9 100644 --- a/google-cloud-storage_batch_operations/samples/storage_batch_get_job.rb +++ b/google-cloud-storage_batch_operations/samples/storage_batch_get_job.rb @@ -11,7 +11,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -require "google/cloud/storage_batch_operations" # [START storage_batch_get_job] def get_job project_name:, job_name: diff --git a/google-cloud-storage_batch_operations/samples/storage_batch_list_job.rb b/google-cloud-storage_batch_operations/samples/storage_batch_list_job.rb index 6a4316eb5c17..6df9722bd350 100644 --- a/google-cloud-storage_batch_operations/samples/storage_batch_list_job.rb +++ b/google-cloud-storage_batch_operations/samples/storage_batch_list_job.rb @@ -27,4 +27,4 @@ def list_job project_name: end # [END storage_batch_list_job] -delete_job project_name: ARGV.shift, job_name: ARGV.shift if $PROGRAM_NAME == __FILE__ +list_job project_name: ARGV.shift if $PROGRAM_NAME == __FILE__ \ No newline at end of file