Skip to content
This repository has been archived by the owner on Oct 27, 2022. It is now read-only.

Commit

Permalink
Merge pull request #932 from dmlond/DDS-811_batch_retries-prod
Browse files Browse the repository at this point in the history
[Production] DDS-811 batch retries
  • Loading branch information
dmann committed Feb 17, 2017
2 parents 97f5f6d + 5741fb1 commit 8656bfb
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions lib/tasks/elasticsearch.rake
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,27 @@ def index_documents
data: f.__elasticsearch__.as_indexed_json }
}
}
Elasticsearch::Model.client.bulk body: current_batch
$stderr.print "+" * current_batch.length
trys = 0
error_ids = []
while trys < 5
bulk_response = Elasticsearch::Model.client.bulk body: current_batch
if bulk_response["errors"]
trys += 1
error_ids = bulk_response["items"].select {|item|
item["index"]["status"] >= 400
}.map {|i|
i["index"]["_id"]
}
current_batch = current_batch.select {|b| error_ids.include? b[:index][:_id] }
else
trys = 5
end
end
unless error_ids.empty?
$stderr.puts "page #{page_num} Ids Not Loaded after #{trys} tries:"
$stderr.puts error_ids.join(',')
end
$stderr.print "+" * (current_batch.length - error_ids.length)
end
end
end
Expand Down

0 comments on commit 8656bfb

Please sign in to comment.