Class: AzureClient::Container
- Inherits:
-
Object
- Object
- AzureClient::Container
- Defined in:
- lib/azure_client/container.rb
Constant Summary collapse
- BLOB_SIZE_LIMIT =
actual limit is 64 MB
1024 * 1024 * 60
- BLOCK_SIZE_LIMIT =
actual limit is 4 MB
1024 * 1024 * 3
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #delete(retry_policy = @retry_policy) ⇒ Object
- #delete_blob(blob_name, retry_policy = @retry_policy) ⇒ Object
-
#get_blob(blob_name, options = {}, retry_policy = @retry_policy) ⇒ Object
throws exception if no blob found.
- #get_blob_lease(blob_name, retry_policy = @retry_policy, options = {}) ⇒ Object
- #get_blob_metadata(blob_name, retry_policy = @retry_policy) ⇒ Object
- #get_blob_properties(blob_name, retry_policy = @retry_policy) ⇒ Object
-
#initialize(name, blob_service, retry_policy) ⇒ Container
constructor
A new instance of Container.
- #list_blobs(options = {}, retry_policy = @retry_policy) ⇒ Object
- #poll_blob(blob_name, key, val, polling_policy = ExponentialRetryPolicy.new(75,5,1.1)) ⇒ Object
- #set_blob_metadata(blob_name, metadata, retry_policy = @retry_policy) ⇒ Object
-
#store_blob(blob_name, content, options = {}, retry_policy = @retry_policy) ⇒ Object
will overwrite content if blob with same name already exists.
Constructor Details
#initialize(name, blob_service, retry_policy) ⇒ Container
Returns a new instance of Container.
8 9 10 11 12 |
# File 'lib/azure_client/container.rb', line 8 def initialize(name, blob_service, retry_policy) @name = name @blob_service = blob_service @retry_policy = retry_policy end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/azure_client/container.rb', line 6 def name @name end |
Instance Method Details
#delete(retry_policy = @retry_policy) ⇒ Object
61 62 63 64 65 |
# File 'lib/azure_client/container.rb', line 61 def delete(retry_policy = @retry_policy) retry_policy.retry { @blob_service.delete_container(@name) } end |
#delete_blob(blob_name, retry_policy = @retry_policy) ⇒ Object
67 68 69 70 71 |
# File 'lib/azure_client/container.rb', line 67 def delete_blob(blob_name, retry_policy = @retry_policy) retry_policy.retry { @blob_service.delete_blob(name, blob_name) } end |
#get_blob(blob_name, options = {}, retry_policy = @retry_policy) ⇒ Object
throws exception if no blob found
32 33 34 35 36 37 |
# File 'lib/azure_client/container.rb', line 32 def get_blob(blob_name, = {}, retry_policy = @retry_policy) retry_policy.retry { azure_blob, content = @blob_service.get_blob(name, blob_name, ) Blob.new(blob_name, azure_blob, content, name, @blob_service, @retry_policy) } end |
#get_blob_lease(blob_name, retry_policy = @retry_policy, options = {}) ⇒ Object
39 40 41 |
# File 'lib/azure_client/container.rb', line 39 def get_blob_lease(blob_name, retry_policy = @retry_policy, = {}) BlobLease.new(@name, blob_name, @blob_service, retry_policy, ) end |
#get_blob_metadata(blob_name, retry_policy = @retry_policy) ⇒ Object
49 50 51 52 53 |
# File 'lib/azure_client/container.rb', line 49 def (blob_name, retry_policy = @retry_policy) retry_policy.retry { @blob_service.(@name, blob_name). } end |
#get_blob_properties(blob_name, retry_policy = @retry_policy) ⇒ Object
43 44 45 46 47 |
# File 'lib/azure_client/container.rb', line 43 def get_blob_properties(blob_name, retry_policy = @retry_policy) retry_policy.retry { @blob_service.get_blob_properties(@name, blob_name) }.properties end |
#list_blobs(options = {}, retry_policy = @retry_policy) ⇒ Object
14 15 16 17 18 |
# File 'lib/azure_client/container.rb', line 14 def list_blobs( = {}, retry_policy = @retry_policy) retry_policy.retry { @blob_service.list_blobs(name, ) } end |
#poll_blob(blob_name, key, val, polling_policy = ExponentialRetryPolicy.new(75,5,1.1)) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/azure_client/container.rb', line 73 def poll_blob(blob_name, key, val, polling_policy = ExponentialRetryPolicy.new(75,5,1.1)) start_time = Time.now #create blob if it does not exist begin blob = get_blob(blob_name) rescue store_blob(blob_name,"") end polling_policy.retry { puts "*** polling Azure blob #{blob_name} for #{Time.now - start_time} seconds" = (blob_name) if && [key] == val then return val else raise "Polled the blob #{blob_name} for #{Time.now - start_time} seconds. Time out!" end } end |
#set_blob_metadata(blob_name, metadata, retry_policy = @retry_policy) ⇒ Object
55 56 57 58 59 |
# File 'lib/azure_client/container.rb', line 55 def (blob_name, , retry_policy = @retry_policy) retry_policy.retry { @blob_service.(@name, blob_name, ) } end |
#store_blob(blob_name, content, options = {}, retry_policy = @retry_policy) ⇒ Object
will overwrite content if blob with same name already exists
21 22 23 24 25 26 27 28 29 |
# File 'lib/azure_client/container.rb', line 21 def store_blob(blob_name, content, = {}, retry_policy = @retry_policy) if content.kind_of?(String) store_string_to_blob(blob_name, content, , retry_policy) elsif content.kind_of?(IO) store_io_to_blob(blob_name, content, , retry_policy) else raise "Trying to upload unknown type #{content.class} into Azure, only String/IO allowed!" end end |