Class: Etna::Clients::Metis::MetisUploadWorkflow

Inherits:
Struct
  • Object
show all
Defined in:
lib/etna/clients/metis/workflows/metis_upload_workflow.rb

Defined Under Namespace

Classes: StreamingIOUpload, StreamingUploadError, Upload

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ MetisUploadWorkflow

Returns a new instance of MetisUploadWorkflow.



17
18
19
# File 'lib/etna/clients/metis/workflows/metis_upload_workflow.rb', line 17

def initialize(args)
  super({max_attempts: 3, metis_uid: SecureRandom.hex}.update(args))
end

Instance Attribute Details

#bucket_nameObject

Returns the value of attribute bucket_name

Returns:

  • (Object)

    the current value of bucket_name



12
13
14
# File 'lib/etna/clients/metis/workflows/metis_upload_workflow.rb', line 12

def bucket_name
  @bucket_name
end

#max_attemptsObject

Returns the value of attribute max_attempts

Returns:

  • (Object)

    the current value of max_attempts



12
13
14
# File 'lib/etna/clients/metis/workflows/metis_upload_workflow.rb', line 12

def max_attempts
  @max_attempts
end

#metis_clientObject

Returns the value of attribute metis_client

Returns:

  • (Object)

    the current value of metis_client



12
13
14
# File 'lib/etna/clients/metis/workflows/metis_upload_workflow.rb', line 12

def metis_client
  @metis_client
end

#metis_uidObject

Returns the value of attribute metis_uid

Returns:

  • (Object)

    the current value of metis_uid



12
13
14
# File 'lib/etna/clients/metis/workflows/metis_upload_workflow.rb', line 12

def metis_uid
  @metis_uid
end

#project_nameObject

Returns the value of attribute project_name

Returns:

  • (Object)

    the current value of project_name



12
13
14
# File 'lib/etna/clients/metis/workflows/metis_upload_workflow.rb', line 12

def project_name
  @project_name
end

Instance Method Details

#do_upload(source_file_or_upload, dest_path, &block) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/etna/clients/metis/workflows/metis_upload_workflow.rb', line 21

def do_upload(source_file_or_upload, dest_path, &block)
  unless source_file_or_upload.is_a?(Upload)
    upload = Upload.new(source_file: source_file_or_upload)
  else
    upload = source_file_or_upload
  end

  dir = ::File.dirname(dest_path)
  metis_client.create_folder(CreateFolderRequest.new(
      project_name: project_name,
      bucket_name: bucket_name,
      folder_path: dir,
  )) unless dir == "."

  authorize_response = metis_client.authorize_upload(AuthorizeUploadRequest.new(
      project_name: project_name,
      bucket_name: bucket_name,
      file_path: dest_path,
  ))

  upload_parts(upload, authorize_response.upload_path, &block)
end