Skip to content

Commit

Permalink
fix: retry get_tarball on error
Browse files Browse the repository at this point in the history
Signed-off-by: Guillaume Hivert <[email protected]>
  • Loading branch information
ghivert committed May 21, 2024
1 parent b856030 commit ef74cdc
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions apps/backend/src/api/hex_repo.gleam
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import backend/error
import gleam/bit_array
import gleam/erlang/process
import gleam/http
import gleam/http/request
import gleam/httpc
Expand Down Expand Up @@ -89,8 +90,14 @@ fn get_tarball(name: String, version: String) {
|> request.set_scheme(http.Https)
|> httpc.send_bits()
|> result.map_error(error.FetchError)
|> result.map(fn(res) {
create_archive(archives_path, name, version, res.body)
|> result.try(fn(res) {
case res.status {
200 -> Ok(create_archive(archives_path, name, version, res.body))
_ -> {
process.sleep(1000)
get_tarball(name, version)
}
}
})
}

Expand Down

0 comments on commit ef74cdc

Please sign in to comment.