Skip to content
This repository has been archived by the owner on May 14, 2021. It is now read-only.

Commit

Permalink
Refactor doc polling as new method
Browse files Browse the repository at this point in the history
  • Loading branch information
dkerwin committed Mar 18, 2014
1 parent f0a1584 commit ea49f0c
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions lib/gini-api/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,15 +160,9 @@ def upload(file, &block)
# Start polling (0.5s) when document has been uploaded successfully
if response.status == 201
doc = Gini::Api::Document.new(self, response.headers['location'])
duration[:processing] = poll_document(doc, &block)

timeout(@processing_timeout) do
duration[:processing] = Benchmark.realtime do
doc.poll(&block)
end
end

# Combine duration values and update doc object
duration[:total] = duration[:upload] + duration[:processing]
duration[:total] = duration.values.inject(:+)
doc.duration = duration

doc
Expand Down Expand Up @@ -278,6 +272,22 @@ def resource_to_location(resource)
)
end

# Poll document and duration
#
# @param [Gini::Api::Document] doc Document instance to poll
#
# @return [Integer] Processing duration
#
def poll_document(doc, &block)
duration = 0
timeout(@processing_timeout) do
duration = Benchmark.realtime do
doc.poll(&block)
end
end
duration
end

# Helper to upload document
#
# @param [String] file location of document to be uploaded
Expand Down

0 comments on commit ea49f0c

Please sign in to comment.