From 0a6ea615a676c9a806fb13b0a8444d1a2cd05346 Mon Sep 17 00:00:00 2001 From: Thales Macedo Garitezi Date: Thu, 19 Sep 2024 16:17:59 -0300 Subject: [PATCH] feat: retry sending report when coveralls returns 502 Frequently, coveralls replies with a 502 HTTP status code response. Instead of failing the whole CI run for such transient errors, we add a sleep + retry here, limited to 5 extra attempts. --- src/coveralls.erl | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/coveralls.erl b/src/coveralls.erl index f35475b..251fffa 100644 --- a/src/coveralls.erl +++ b/src/coveralls.erl @@ -104,7 +104,10 @@ convert_file([[_|_]|_]=Filenames, Report, S) -> convert_and_send_file(Filenames, Report, S) -> send(convert_file(Filenames, Report, S), S). -send(Json, #s{poster=Poster, poster_init=Init}) -> +send(Json, S) -> + send(Json, S, _AttemptsLeft = 5). + +send(Json, #s{poster=Poster, poster_init=Init} = S, AttemptsLeft) -> ok = Init(), Boundary = ["----------", integer_to_list(?random:uniform(1000))], Type = "multipart/form-data; boundary=" ++ Boundary, @@ -115,6 +118,11 @@ send(Json, #s{poster=Poster, poster_init=Init}) -> case ReturnCode of 200 -> ok; + 502 -> + case AttemptsLeft > 0 of + true -> timer:sleep(1_000), send(Json, S, AttemptsLeft - 1); + false -> throw({error, {ReturnCode, Message}}) + end; ErrCode -> throw({error, {ErrCode, Message}}) end.