Method: IntelligentUtils#run_intelligent_uploads

Defined in:
lib/filestack/utils/utils.rb

#run_intelligent_uploads(part, filepath, io, state, storage) ⇒ IntelligentState

Send a job’s chunks in parallel and commit

Parameters:

  • part (Dict)

    A dictionary representing the information for a single part

  • state (IntelligentState)

    An IntelligentState object

Returns:



312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
# File 'lib/filestack/utils/utils.rb', line 312

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 StandardError => 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