Class: BlockActor

Inherits:
Object
  • Object
show all
Includes:
Celluloid
Defined in:
lib/azure-contrib/blob_service.rb

Overview

Instance Method Summary collapse

Constructor Details

#initialize(service, container, blob, options = {}) ⇒ BlockActor

Returns a new instance of BlockActor.



20
21
22
# File 'lib/azure-contrib/blob_service.rb', line 20

def initialize(service, container, blob, options = {})
  @service, @container, @blob, @options = service, container, blob, options
end

Instance Method Details

#log(message) ⇒ Object



43
44
45
# File 'lib/azure-contrib/blob_service.rb', line 43

def log(message)
  puts message
end

#upload(block_id, chunk, retries = 0) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/azure-contrib/blob_service.rb', line 24

def upload(block_id, chunk, retries = 0)
  Timeout::timeout(@options[:timeout] || 30){
    log "Uploading block #{block_id}"
    options = @options.dup
    options[:content_md5] = Base64.strict_encode64(Digest::MD5.digest(chunk))
    content_md5 = @service.create_blob_block(@container, @blob, block_id, chunk, options)
    log "Done uploading block #{block_id} #{content_md5}"
    [block_id, :uncommitted]
  }
rescue Timeout::Error, Azure::Core::Error => e
  log "Failed to upload #{block_id}: #{e.class} #{e.message}"
  if retries < 5
    log "Retrying upload (#{retries})"
    upload(block_id, chunk, retries += 1)
  else
    log "Complete failure to upload #{retries} retries"
  end
end