Skip to content

Commit

Permalink
Merge pull request #4 from thalesmg/retry-502
Browse files Browse the repository at this point in the history
feat: retry sending report when coveralls returns 502
  • Loading branch information
zmstone authored Sep 19, 2024
2 parents cd86080 + 0a6ea61 commit 6402d51
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/coveralls.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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.

Expand Down

0 comments on commit 6402d51

Please sign in to comment.