Skip to content

Commit

Permalink
Fix RelevanceTests
Browse files Browse the repository at this point in the history
  • Loading branch information
adpi2 committed Aug 19, 2024
1 parent 0da28b8 commit df444f4
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion modules/data/src/main/resources/subindex.txt
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ foundweekends/giter8
cb372/scalacache
blemale/scaffeine
scala/scala
lampepfl/dotty
scala/scala3
sbt/zinc
scala-js/scala-js
scala-native/scala-native
Expand Down
4 changes: 3 additions & 1 deletion modules/server/src/it/scala/scaladex/RelevanceTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import scaladex.server.service.SearchSynchronizer
import scaladex.core.model.search.PageParams
import scaladex.server.service.DependencyUpdater
import scaladex.core.service.ProjectService
import scaladex.server.service.ArtifactService

class RelevanceTest extends TestKit(ActorSystem("SbtActorTest")) with AsyncFunSuiteLike with BeforeAndAfterAll {

Expand All @@ -40,12 +41,13 @@ class RelevanceTest extends TestKit(ActorSystem("SbtActorTest")) with AsyncFunSu
val projectService = new ProjectService(database)
val searchSync = new SearchSynchronizer(database, projectService, searchEngine)
val projectDependenciesUpdater = new DependencyUpdater(database, projectService)
val artifactService = new ArtifactService(database)

IO.fromFuture(IO {
for {
_ <- Init.run(database, filesystem)
_ <- searchEngine.init(true)
_ <- projectDependenciesUpdater.updateAll()
_ <- artifactService.updateAllLatestVersions().zip(projectDependenciesUpdater.updateAll())
_ <- searchSync.syncAll()
_ <- searchEngine.refresh()
} yield ()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import scaladex.core.service.SearchEngine
import scaladex.core.web.ArtifactPageParams
import scaladex.core.web.ArtifactsPageParams
import scaladex.server.TwirlSupport._
import scaladex.server.service.ArtifactsService
import scaladex.server.service.ArtifactService
import scaladex.server.service.SearchSynchronizer
import scaladex.view.html.forbidden
import scaladex.view.html.notfound
Expand All @@ -31,7 +31,7 @@ class ProjectPages(env: Env, database: SchedulerDatabase, searchEngine: SearchEn
implicit executionContext: ExecutionContext
) extends LazyLogging {
private val projectService = new ProjectService(database)
private val artifactsService = new ArtifactsService(database)
private val artifactService = new ArtifactService(database)
private val searchSynchronizer = new SearchSynchronizer(database, projectService, searchEngine)

def route(user: Option[UserState]): Route =
Expand Down Expand Up @@ -158,7 +158,7 @@ class ProjectPages(env: Env, database: SchedulerDatabase, searchEngine: SearchEn
editForm { form =>
val updateF = for {
_ <- database.updateProjectSettings(projectRef, form)
_ <- artifactsService.updateLatestVersions(projectRef, form.preferStableVersion)
_ <- artifactService.updateLatestVersions(projectRef, form.preferStableVersion)
_ <- searchSynchronizer.syncProject(projectRef)
} yield ()
onComplete(updateF) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ class AdminService(
val searchSynchronizer = new SearchSynchronizer(database, projectService, searchEngine)
val projectDependenciesUpdater = new DependencyUpdater(database, projectService)
val userSessionService = new UserSessionService(database)
val artifactsService = new ArtifactsService(database)
val artifactService = new ArtifactService(database)
val githubUpdaterOpt: Option[GithubUpdater] = githubClientOpt.map(client => new GithubUpdater(database, client))

private val jobs: Map[String, JobScheduler] = {
val seq = Seq(
new JobScheduler(Job.syncSearch, searchSynchronizer.syncAll),
new JobScheduler(Job.projectDependencies, projectDependenciesUpdater.updateAll),
new JobScheduler(Job.projectCreationDates, updateProjectCreationDate),
new JobScheduler(Job.moveArtifacts, artifactsService.moveAll),
new JobScheduler(Job.moveArtifacts, artifactService.moveAll),
new JobScheduler(Job.userSessions, userSessionService.updateAll),
new JobScheduler(Job.latestArtifacts, artifactsService.updateAllLatestVersions)
new JobScheduler(Job.latestArtifacts, artifactService.updateAllLatestVersions)
) ++
githubClientOpt.map { client =>
val githubUpdater = new GithubUpdater(database, client)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import scaladex.core.model._
import scaladex.core.service.SchedulerDatabase
import scaladex.core.util.ScalaExtensions._

class ArtifactsService(database: SchedulerDatabase)(implicit ec: ExecutionContext) extends LazyLogging {
class ArtifactService(database: SchedulerDatabase)(implicit ec: ExecutionContext) extends LazyLogging {
def insertArtifact(artifact: Artifact, dependencies: Seq[ArtifactDependency]): Future[Boolean] = {
val unknownStatus = GithubStatus.Unknown(Instant.now)
for {
Expand Down Expand Up @@ -40,6 +40,7 @@ class ArtifactsService(database: SchedulerDatabase)(implicit ec: ExecutionContex
for {
projectStatuses <- database.getAllProjectsStatuses()
refs = projectStatuses.collect { case (ref, status) if status.isOk || status.isUnknown || status.isFailed => ref }
_ = logger.info(s"Updating latest versions of ${refs.size} projects")
total <- refs.mapSync(updateLatestVersions).map(_.sum)
} yield s"Updated $total artifacts in ${refs.size} projects"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class PublishProcess(
githubExtractor: GithubRepoExtractor,
converter: ArtifactConverter,
database: WebDatabase,
artifactsService: ArtifactsService,
artifactService: ArtifactService,
pomsReader: PomsReader,
env: Env
)(implicit system: ActorSystem)
Expand Down Expand Up @@ -78,7 +78,7 @@ class PublishProcess(
converter.convert(pom, repo, creationDate) match {
case Some((artifact, deps)) =>
for {
isNewProject <- artifactsService.insertArtifact(artifact, deps)
isNewProject <- artifactService.insertArtifact(artifact, deps)
_ <-
if (isNewProject && userState.nonEmpty) {
val githubUpdater = new GithubUpdater(database, new GithubClientImpl(userState.get.info.token))
Expand Down Expand Up @@ -108,7 +108,7 @@ object PublishProcess {
val githubExtractor = new GithubRepoExtractor(paths)
val converter = new ArtifactConverter(paths)
val pomsReader = new PomsReader(new CoursierResolver)
val artifactsService = new ArtifactsService(database)
new PublishProcess(filesystem, githubExtractor, converter, database, artifactsService, pomsReader, env)
val artifactService = new ArtifactService(database)
new PublishProcess(filesystem, githubExtractor, converter, database, artifactService, pomsReader, env)
}
}

0 comments on commit df444f4

Please sign in to comment.