Class: AzureClient::Container

Inherits:
Object
  • Object
show all
Defined in:
lib/azure_client/container.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, blob_service, retry_policy) ⇒ Container

Returns a new instance of Container.



5
6
7
8
9
# File 'lib/azure_client/container.rb', line 5

def initialize(name, blob_service, retry_policy)
  @name = name
  @blob_service = blob_service
  @retry_policy = retry_policy
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/azure_client/container.rb', line 3

def name
  @name
end

Instance Method Details

#delete(retry_policy = @retry_policy) ⇒ Object



48
49
50
51
52
# File 'lib/azure_client/container.rb', line 48

def delete(retry_policy = @retry_policy)
  retry_policy.retry {
    @blob_service.delete_container(@name) 
  }
end

#delete_blob(blob_name, retry_policy = @retry_policy) ⇒ Object



54
55
56
57
58
# File 'lib/azure_client/container.rb', line 54

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



19
20
21
22
23
24
# File 'lib/azure_client/container.rb', line 19

def get_blob(blob_name, options = {}, retry_policy = @retry_policy) 
  retry_policy.retry {
    azure_blob, content = @blob_service.get_blob(name, blob_name, options)
    Blob.new(blob_name, azure_blob, content, name, @blob_service, @retry_policy)
  }
end

#get_blob_lease(blob_name, retry_policy = @retry_policy, options = {}) ⇒ Object



26
27
28
# File 'lib/azure_client/container.rb', line 26

def get_blob_lease(blob_name, retry_policy = @retry_policy, options = {})
  BlobLease.new(@name, blob_name, @blob_service, retry_policy, options)
end

#get_blob_metadata(blob_name, retry_policy = @retry_policy) ⇒ Object



36
37
38
39
40
# File 'lib/azure_client/container.rb', line 36

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



30
31
32
33
34
# File 'lib/azure_client/container.rb', line 30

def get_blob_properties(blob_name, retry_policy = @retry_policy)
  retry_policy.retry {
    @blob_service.get_blob_properties(@name, blob_name)
  }.properties
end

#poll_blob(blob_name, key, val, timeout = 10800) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/azure_client/container.rb', line 60

def poll_blob(blob_name, key, val, timeout = 10800)
  time = 0
  #create blob if it does not exist
  begin
    blob = get_blob(blob_name)
  rescue
    store_blob(blob_name,"")
  end
  loop do 
    sleep(5)
    time += 5;
    puts "*** polling Azure blob #{blob_name} for #{time} seconds"
     = (blob_name)
    return val if  && [key] == val
    if time > timeout
      raise "Polling blob #{blob_name} took more than #{timeout} seconds to run. Time out."
    end
  end
end

#set_blob_metadata(blob_name, metadata, retry_policy = @retry_policy) ⇒ Object



42
43
44
45
46
# File 'lib/azure_client/container.rb', line 42

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



12
13
14
15
16
# File 'lib/azure_client/container.rb', line 12

def store_blob(blob_name, content, options = {}, retry_policy = @retry_policy)
  retry_policy.retry {
    @blob_service.create_block_blob(name, blob_name, content, options)
  }
end