Class: AzureClient::BlobLease
- Inherits:
-
Object
- Object
- AzureClient::BlobLease
- Defined in:
- lib/azure_client/blob_lease.rb
Constant Summary collapse
- RENEW_MARGIN =
10
Instance Attribute Summary collapse
-
#blob_name ⇒ Object
readonly
Returns the value of attribute blob_name.
-
#container ⇒ Object
readonly
Returns the value of attribute container.
-
#duration ⇒ Object
readonly
Returns the value of attribute duration.
-
#lease_id ⇒ Object
(also: #name)
readonly
Returns the value of attribute lease_id.
-
#start_time ⇒ Object
readonly
Returns the value of attribute start_time.
Instance Method Summary collapse
- #change(new_lease_id, retry_policy = @retry_policy) ⇒ Object
-
#initialize(container, blob_name, blob_service, retry_policy, options = {}) ⇒ BlobLease
constructor
A new instance of BlobLease.
- #release(retry_policy = @retry_policy) ⇒ Object
- #renew(retry_policy = @retry_policy) ⇒ Object
- #renew_if_necessary(retry_policy = nil) ⇒ Object
Constructor Details
#initialize(container, blob_name, blob_service, retry_policy, options = {}) ⇒ BlobLease
Returns a new instance of BlobLease.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/azure_client/blob_lease.rb', line 9 def initialize(container, blob_name, blob_service, retry_policy, = {}) @container = container @blob_name = blob_name @blob_service = blob_service @retry_policy = retry_policy [:duration] ||= 60 # NO default to infinity retry_policy.retry { tries = 0 begin @lease_id = @blob_service.acquire_lease(container, blob_name, ) rescue Azure::Core::Http::HTTPError => e if tries < 1 and e.status_code == 404 then @blob_service.create_block_blob(container, blob_name, '') tries += 1 retry else raise end end } @start_time = Time.now @duration = [:duration] end |
Instance Attribute Details
#blob_name ⇒ Object (readonly)
Returns the value of attribute blob_name.
5 6 7 |
# File 'lib/azure_client/blob_lease.rb', line 5 def blob_name @blob_name end |
#container ⇒ Object (readonly)
Returns the value of attribute container.
5 6 7 |
# File 'lib/azure_client/blob_lease.rb', line 5 def container @container end |
#duration ⇒ Object (readonly)
Returns the value of attribute duration.
5 6 7 |
# File 'lib/azure_client/blob_lease.rb', line 5 def duration @duration end |
#lease_id ⇒ Object (readonly) Also known as: name
Returns the value of attribute lease_id.
5 6 7 |
# File 'lib/azure_client/blob_lease.rb', line 5 def lease_id @lease_id end |
#start_time ⇒ Object (readonly)
Returns the value of attribute start_time.
5 6 7 |
# File 'lib/azure_client/blob_lease.rb', line 5 def start_time @start_time end |
Instance Method Details
#change(new_lease_id, retry_policy = @retry_policy) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/azure_client/blob_lease.rb', line 34 def change(new_lease_id, retry_policy = @retry_policy) retry_policy.retry { @blob_service.change_lease(container, blob_name, "#{new_lease_id}", lease_id) @lease_id = new_lease_id } end |
#release(retry_policy = @retry_policy) ⇒ Object
52 53 54 55 56 |
# File 'lib/azure_client/blob_lease.rb', line 52 def release(retry_policy = @retry_policy) retry_policy.retry { @blob_service.release_lease(container, blob_name, lease_id) } end |
#renew(retry_policy = @retry_policy) ⇒ Object
41 42 43 44 45 |
# File 'lib/azure_client/blob_lease.rb', line 41 def renew(retry_policy = @retry_policy) retry_policy.retry { @blob_service.renew_lease(container, blob_name, lease_id) } end |
#renew_if_necessary(retry_policy = nil) ⇒ Object
47 48 49 50 |
# File 'lib/azure_client/blob_lease.rb', line 47 def renew_if_necessary(retry_policy = nil) age = Time.now - start_time renew(retry_policy) if duration - age <= RENEW_MARGIN end |