Skip to content

Commit 23ee3d3

Browse files
wip
1 parent 5bbe50b commit 23ee3d3

4 files changed

Lines changed: 26 additions & 21 deletions

File tree

google-cloud-storage-control-v2/lib/google/cloud/storage/control/v2/storage_control/operations.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ def get_operation request, options = nil
283283

284284
# Customize the options with defaults
285285
metadata = @config.rpcs.get_operation.metadata.to_h
286+
binding.pry
286287

287288
# Set x-goog-api-client, x-goog-user-project and x-goog-api-version headers
288289
metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
@@ -304,7 +305,6 @@ def get_operation request, options = nil
304305
retry_policy: @config.rpcs.get_operation.retry_policy
305306

306307
options.apply_defaults timeout: @config.timeout,
307-
metadata: @config.metadata,
308308
retry_policy: @config.retry_policy
309309

310310
@operations_stub.call_rpc :get_operation, request, options: options do |response, operation|

google-cloud-storage-control/samples/acceptance/helper.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@ def random_folder_name prefix: "ruby-storage-control-folder-samples-test-"
2626
t = Time.now.utc.iso8601.gsub ":", "-"
2727
"#{prefix}-#{t}-#{SecureRandom.hex 4}".downcase
2828
end
29+
def storage_client
30+
@storage_client ||= Google::Cloud::Storage.new
31+
end
2932

3033
def create_bucket_helper bucket_name, uniform_bucket_level_access: nil, hierarchical_namespace: nil
31-
storage_client = Google::Cloud::Storage.new
3234
retry_resource_exhaustion do
3335
storage_client.create_bucket bucket_name do |b|
3436
b.uniform_bucket_level_access = uniform_bucket_level_access
@@ -38,7 +40,6 @@ def create_bucket_helper bucket_name, uniform_bucket_level_access: nil, hierarch
3840
end
3941

4042
def delete_bucket_helper bucket_name
41-
storage_client = Google::Cloud::Storage.new
4243
retry_resource_exhaustion do
4344
bucket = storage_client.bucket bucket_name
4445
return unless bucket

google-cloud-storage-control/samples/acceptance/storage_control_anywhere_cache_test.rb

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
require_relative "../storage_control_pause_anywhere_cache"
2222
require_relative "../storage_control_resume_anywhere_cache"
2323
require_relative "../storage_control_disable_anywhere_cache"
24+
require 'pry'
2425

2526
describe "Storage Control Anywhere Cache" do
2627
let(:bucket_name) { random_bucket_name }
@@ -29,11 +30,11 @@
2930
let(:anywhere_cache_name) { "projects/_/buckets/#{bucket_name}/anywhereCaches/#{zone}" }
3031

3132
before :all do
32-
@bucket = create_bucket_helper bucket_name
33+
bucket = create_bucket_helper bucket_name
3334
end
3435

35-
after do
36-
delete_bucket_helper bucket_name until count_anywhere_caches(bucket_name).zero?
36+
after :all do
37+
delete_bucket_helper bucket_name #{}until count_anywhere_caches(bucket_name).zero?
3738
end
3839

3940
it "handles Anywhere cache lifecycle in sequence" do
@@ -74,14 +75,14 @@
7475
end
7576
end
7677

77-
def count_anywhere_caches bucket_name
78-
sleep 900
79-
storage_control_client = Google::Cloud::Storage::Control.storage_control
80-
# Set project to "_" to signify global bucket
81-
parent = "projects/_/buckets/#{bucket_name}"
82-
request = Google::Cloud::Storage::Control::V2::ListAnywhereCachesRequest.new(
83-
parent: parent
84-
)
85-
result = storage_control_client.list_anywhere_caches request
86-
result.response.anywhere_caches.count
87-
end
78+
# def count_anywhere_caches bucket_name
79+
# sleep 900
80+
# storage_control_client = Google::Cloud::Storage::Control.storage_control
81+
# # Set project to "_" to signify global bucket
82+
# parent = "projects/_/buckets/#{bucket_name}"
83+
# request = Google::Cloud::Storage::Control::V2::ListAnywhereCachesRequest.new(
84+
# parent: parent
85+
# )
86+
# result = storage_control_client.list_anywhere_caches request
87+
# result.response.anywhere_caches.count
88+
# end

google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,19 @@ def create_anywhere_cache bucket_name:, zone:
4747
name: name
4848
)
4949
result = storage_control_client.get_anywhere_cache get_request
50-
until result.state == "running"
51-
sleep 1800 # Wait for 1/2 hour before checking again
50+
min_delay = 900 # 15 minutes
51+
max_delay = 1800 # 30 minutes
52+
while result.state != "running"
53+
puts "Cache not running yet, current state is #{result.state}. Retrying in #{min_delay} seconds."
54+
sleep min_delay
55+
min_delay = [min_delay * 2, max_delay].min # Exponential backoff with a max delay
5256
result = storage_control_client.get_anywhere_cache get_request
53-
puts "AnywhereCache status check retried"
5457
end
5558
puts "AnywhereCache created - #{result.name}"
5659
else
5760
puts "AnywhereCache create operation failed"
5861
end
59-
rescue StandardError => e
62+
rescue Google::Cloud::Error=> e
6063
puts "Error creating AnywhereCache: #{e.message}"
6164
end
6265
end

0 commit comments

Comments
 (0)