[PATCH compass-ci] lib/git_mirror.rb: retry es query

[errmsg] git-mirror: /usr/lib/ruby/2.5.0/socket.rb:452:in `__read_nonblock': Connection reset by peer (Faraday::ConnectionFailed) Sometimes the error above occurs, and container git-mirror restart. It's not a stable error, and next time es query can be success. So retry here. Signed-off-by: Li Yuanchao <lyc163mail@163.com> --- lib/git_mirror.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/git_mirror.rb b/lib/git_mirror.rb index bcdb077..6100d6b 100644 --- a/lib/git_mirror.rb +++ b/lib/git_mirror.rb @@ -432,7 +432,14 @@ class MirrorMain query = { query: { match: { _id: git_repo } } } return fork_stat unless @es_client.count(index: 'repo', body: query)['count'].positive? - result = @es_client.search(index: 'repo', body: query)['hits'] + begin + result = @es_client.search(index: 'repo', body: query)['hits'] + rescue StandardError + puts $ERROR_INFO + sleep 1 + retry + end + fork_stat.each_key do |key| fork_stat[key] = result['hits'][0]['_source'][key.to_s] || fork_stat[key] end -- 2.23.0
participants (1)
-
Li Yuanchao