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

Commit 8656bfb

Browse files
authored
Merge pull request #932 from dmlond/DDS-811_batch_retries-prod
[Production] DDS-811 batch retries
2 parents 97f5f6d + 5741fb1 commit 8656bfb

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

lib/tasks/elasticsearch.rake

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,27 @@ def index_documents
3333
data: f.__elasticsearch__.as_indexed_json }
3434
}
3535
}
36-
Elasticsearch::Model.client.bulk body: current_batch
37-
$stderr.print "+" * current_batch.length
36+
trys = 0
37+
error_ids = []
38+
while trys < 5
39+
bulk_response = Elasticsearch::Model.client.bulk body: current_batch
40+
if bulk_response["errors"]
41+
trys += 1
42+
error_ids = bulk_response["items"].select {|item|
43+
item["index"]["status"] >= 400
44+
}.map {|i|
45+
i["index"]["_id"]
46+
}
47+
current_batch = current_batch.select {|b| error_ids.include? b[:index][:_id] }
48+
else
49+
trys = 5
50+
end
51+
end
52+
unless error_ids.empty?
53+
$stderr.puts "page #{page_num} Ids Not Loaded after #{trys} tries:"
54+
$stderr.puts error_ids.join(',')
55+
end
56+
$stderr.print "+" * (current_batch.length - error_ids.length)
3857
end
3958
end
4059
end

0 commit comments

Comments
 (0)