From 922428b433856f544774e7068c5df10abf4bc4c6 Mon Sep 17 00:00:00 2001 From: Guillaume Hivert Date: Sun, 5 May 2024 20:05:38 +0200 Subject: [PATCH] fix: skip retired packages Signed-off-by: Guillaume Hivert --- apps/backend/src/tasks/hex.gleam | 46 +++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 13 deletions(-) diff --git a/apps/backend/src/tasks/hex.gleam b/apps/backend/src/tasks/hex.gleam index 6903e82..ba6ae4a 100644 --- a/apps/backend/src/tasks/hex.gleam +++ b/apps/backend/src/tasks/hex.gleam @@ -127,20 +127,40 @@ fn insert_package_and_releases( wisp.log_info("Saving releases for " <> package.name) list.try_each(releases, fn(r) { use _ <- result.map(queries.upsert_release(state.db, id, r)) - supervisor.add(children, { - use _ <- supervisor.worker() - retrier.retry(fn() { - let infos = hex_repo.get_package_infos(package.name, r.version) - use #(package, gleam_toml) <- result.try(infos) - case package { - option.None -> Ok([]) - option.Some(package) -> { - let ctx = context.Context(state.db, package, gleam_toml) - signatures.extract_signatures(ctx) - } + case r.retirement { + option.Some(retirement) -> { + let release = package.name <> " v" <> r.version + wisp.log_info("Release " <> release <> " is retired. Skipping.") + case retirement.message { + option.None -> Nil + option.Some(m) -> wisp.log_info(" Retired because " <> m) } - }) - }) + case retirement.reason { + hexpm.OtherReason -> wisp.log_info(" Retired for an other reason") + hexpm.Invalid -> wisp.log_info(" Retired because it was invalid") + hexpm.Security -> wisp.log_info(" Retired for security reasons") + hexpm.Deprecated -> wisp.log_info(" Retired because it's deprecated") + hexpm.Renamed -> wisp.log_info(" Retired because it's renamed") + } + } + option.None -> { + supervisor.add(children, { + use _ <- supervisor.worker() + retrier.retry(fn() { + let infos = hex_repo.get_package_infos(package.name, r.version) + use #(package, gleam_toml) <- result.try(infos) + case package { + option.None -> Ok([]) + option.Some(package) -> { + let ctx = context.Context(state.db, package, gleam_toml) + signatures.extract_signatures(ctx) + } + } + }) + }) + Nil + } + } }) }