~jan0sch/smederee

Showing details for patch 4303da0f408113a8f39a4cc5345c74f72f382984.
2025-05-01 (Thu), 8:17 AM - Jens Grassel - 4303da0f408113a8f39a4cc5345c74f72f382984

vcs: Re-run health check if needed.

- get the timestamp of the latest patch
- re-run the health check automatically if the cached one is older
Summary of changes
1 files modified with 9 lines added and 2 lines removed
  • modules/hub/src/main/scala/de/smederee/hub/VcsRepositoryRoutes.scala with 9 added and 2 removed lines
diff -rN -u old-smederee/modules/hub/src/main/scala/de/smederee/hub/VcsRepositoryRoutes.scala new-smederee/modules/hub/src/main/scala/de/smederee/hub/VcsRepositoryRoutes.scala
--- old-smederee/modules/hub/src/main/scala/de/smederee/hub/VcsRepositoryRoutes.scala	2025-05-06 11:06:25.458773260 +0000
+++ new-smederee/modules/hub/src/main/scala/de/smederee/hub/VcsRepositoryRoutes.scala	2025-05-06 11:06:25.458773260 +0000
@@ -713,8 +713,15 @@
                 case Some(repoId) => vcsMetadataRepo.findHealthCheck(repoId)
                 case _            => Sync[F].pure(None)
             }
-            // TODO: Re-run the health check if the last patch date is newer than the check run date.
-            health <- cachedHealth match {
+            // Get the timestamp for the latest patch.
+            vcsLog  <- darcs.log(directory.toNIO)(repositoryName.toString)(Chain("--last=1", "--xml-output"))
+            xmlLog  <- Sync[F].delay(scala.xml.XML.loadString(vcsLog.stdout.toList.mkString))
+            patches <- Sync[F].delay((xmlLog \ "patch").flatMap(VcsRepositoryPatchMetadata.fromDarcsXmlLog).toList)
+            latestPatch = patches.headOption.map(_.timestamp.toOffsetDateTime)
+            // Re-run the health check if the last patch date is newer than the check run date.
+            health <- cachedHealth.filter(healthCheck =>
+                latestPatch.getOrElse(healthCheck.createdAt).compareTo(healthCheck.createdAt) <= 1
+            ) match {
                 case Some(healthCheck) => Sync[F].pure(healthCheck)
                 case None =>
                     darcs