Skip to content

Commit

Permalink
abandoned -> inactive
Browse files Browse the repository at this point in the history
  • Loading branch information
fthomas committed Jan 23, 2025
1 parent fb06636 commit 4ff5d19
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ final class RepoCacheAlg[F[_]](config: Config)(implicit
data <- maybeCache
.filter(_.sha1 === latestSha1)
.fold(cloneAndRefreshCache(repo, repoOut))(supplementCache(repo, _).pure[F])
_ <- throwIfAbandoned(data)
_ <- throwIfInactive(data)
} yield (data, repoOut)

private def supplementCache(repo: Repo, cache: RepoCache): RepoData =
Expand Down Expand Up @@ -88,12 +88,12 @@ final class RepoCacheAlg[F[_]](config: Config)(implicit
private def gatherDependencyInfo(repo: Repo, dependency: Dependency): F[DependencyInfo] =
gitAlg.findFilesContaining(repo, dependency.version.value).map(DependencyInfo(dependency, _))

private[repocache] def throwIfAbandoned(data: RepoData): F[Unit] =
private[repocache] def throwIfInactive(data: RepoData): F[Unit] =
data.config.lastCommitMaxAge.traverse_ { maxAge =>
dateTimeAlg.currentTimestamp.flatMap { now =>
val sinceLastCommit = data.cache.commitDate.until(now)
val isAbandoned = sinceLastCommit > maxAge
F.raiseWhen(isAbandoned) {
val isInactive = sinceLastCommit > maxAge
F.raiseWhen(isInactive) {
val msg = s"Skipping because last commit is older than ${dateTime.showDuration(maxAge)}"
new Throwable(msg) with NoStackTrace
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,32 +60,32 @@ class RepoCacheAlgTest extends CatsEffectSuite with Http4sDsl[MockEff] {
assertIO(obtained, expected)
}

test("throwIfAbandoned: no maxAge") {
test("throwIfInactive: no maxAge") {
val repo = Repo("repo-cache-alg", "test-1")
val cache = RepoCache(dummySha1, Timestamp(0L), Nil, None, None)
val config = RepoConfig.empty
val data = RepoData(repo, cache, config)
val obtained = repoCacheAlg.throwIfAbandoned(data).runA(MockState.empty).attempt
val obtained = repoCacheAlg.throwIfInactive(data).runA(MockState.empty).attempt
assertIO(obtained, Right(()))
}

test("throwIfAbandoned: lastCommit < maxAge") {
test("throwIfInactive: lastCommit < maxAge") {
val repo = Repo("repo-cache-alg", "test-2")
val commitDate = Timestamp.fromLocalDateTime(LocalDateTime.now())
val cache = RepoCache(dummySha1, commitDate, Nil, None, None)
val config = RepoConfig(lastCommitMaxAge = Some(1.day))
val data = RepoData(repo, cache, config)
val obtained = repoCacheAlg.throwIfAbandoned(data).runA(MockState.empty).attempt
val obtained = repoCacheAlg.throwIfInactive(data).runA(MockState.empty).attempt
assertIO(obtained, Right(()))
}

test("throwIfAbandoned: lastCommit > maxAge") {
test("throwIfInactive: lastCommit > maxAge") {
val repo = Repo("repo-cache-alg", "test-3")
val cache = RepoCache(dummySha1, Timestamp(0L), Nil, None, None)
val config = RepoConfig(lastCommitMaxAge = Some(1.day))
val data = RepoData(repo, cache, config)
val obtained =
repoCacheAlg.throwIfAbandoned(data).runA(MockState.empty).attempt.map(_.leftMap(_.getMessage))
repoCacheAlg.throwIfInactive(data).runA(MockState.empty).attempt.map(_.leftMap(_.getMessage))
assertIO(obtained, Left("Skipping because last commit is older than 1d"))
}
}

0 comments on commit 4ff5d19

Please sign in to comment.