lib/filestack/utils/utils.rb
# Send a job's chunks in parallel and commit
#
# @param [Dict]    part      A dictionary representing the information
#                            for a single part
# @param [IntelligentState]  state     An IntelligentState object
#
# @return [IntelligentState]
Send a job's chunks in parallel and commit
Send a job ' s chunks in parallel and commit
def run_intelligent_uploads(part, filepath, io, state, storage)
    failed = false
    chunks = chunk_job(
      part, state, part[:apikey], part[:filename], part[:filesize], part[:start_response], storage
    )
    Parallel.map(chunks, in_threads: 3) do |chunk|
      begin
        upload_chunk_intelligently(chunk, state, part[:apikey], filepath, io, part[:options], storage)
      rescue => e
        state.error_type = e.message
        failed = true
        Parallel::Kill
      end
    end
    if failed
      state.ok = false
      return state
    else
      state.ok = true
    end
    commit_params = {
      apikey: part[:apikey],
      uri: part[:uri],
      region: part[:region],
      upload_id: part[:upload_id],
      size: part[:filesize],
      part: part[:part],
      location_url: part[:start_response]['location_url'],
      store: { location: storage }
    }
    response = Typhoeus.post(FilestackConfig.multipart_commit_url(commit_params[:location_url]),
                             body: commit_params.to_json,
                             headers: FilestackConfig::HEADERS)
    if response.code == 200
      state.reset
    else
      state.ok = false
    end
    state
  end
def run_intelligent_uploads ( part , filepath , io , state , storage ) failed = false chunks = chunk_job ( part , state , part [ :apikey ] , part [ :filename ] , part [ :filesize ] , part [ :start_response ] , storage ) Parallel . map ( chunks , in_threads : 3 ) do | chunk | begin upload_chunk_intelligently ( chunk , state , part [ :apikey ] , filepath , io , part [ :options ] , storage ) rescue => e state . error_type = e . message failed = true Parallel :: Kill end end if failed state . ok = false return state else state . ok = true end commit_params = { apikey : part [ :apikey ] , uri : part [ :uri ] , region : part [ :region ] , upload_id : part [ :upload_id ] , size : part [ :filesize ] , part : part [ :part ] , location_url : part [ :start_response ] [ 'location_url' ] , store : { location : storage } } response = Typhoeus . post ( FilestackConfig . multipart_commit_url ( commit_params [ :location_url ] ) , body : commit_params . to_json , headers : FilestackConfig :: HEADERS ) if response . code == 200 state . reset else state . ok = false end state end
Send a job's chunks in parallel and commit
Send a job ' s chunks in parallel and commit
None
IntelligentState
part
<not_specific>
filepath
<not_specific>
io
<not_specific>
state
<not_specific>
storage
<not_specific>
<not_specific>
state An IntelligentState object
state An IntelligentState object