Skip to content

Commit

Permalink
Query number of items to wait for
Browse files Browse the repository at this point in the history
  • Loading branch information
eikek committed Jul 11, 2023
1 parent 2981c53 commit b5d1129
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package io.renku.graph.acceptancetests.flows

import cats.data.NonEmptyList
import cats.effect.unsafe.IORuntime
import cats.syntax.all._
import io.renku.events.CategoryName
import io.renku.generators.Generators.Implicits._
import io.renku.graph.acceptancetests.data
Expand Down Expand Up @@ -74,7 +75,9 @@ trait TSProvisioning
sleep((5 seconds).toMillis)
}

`wait for events to be processed`(project.id, accessToken, commitIds.size)
val items = eventLogClient.getEvents(project.id.asLeft).unsafeRunSync().size

`wait for events to be processed`(project.id, accessToken, items)
}

def `wait for events to be processed`(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@ import cats.syntax.all._
import eu.timepit.refined.api.Refined
import eu.timepit.refined.auto._
import eu.timepit.refined.string.Url
import io.circe.Json
import io.circe.generic.extras.JsonKey
import io.circe.generic.semiauto.deriveDecoder
import io.circe.{Decoder, Json}
import io.circe.literal._
import io.renku.control.Throttler
import io.renku.graph.acceptancetests.tooling.ServiceClient.ClientResponse
import io.renku.graph.model.events.{EventId, EventStatus}
import io.renku.graph.model.projects
import io.renku.http.client.{AccessToken, BasicAuthCredentials, RestClient}
import io.renku.http.tinytypes.TinyTypeURIEncoder._
Expand Down Expand Up @@ -120,6 +123,15 @@ object KnowledgeGraphClient {
}

object EventLogClient {
case class ProjectEvent(
id: EventId,
@JsonKey("project.id") projectId: projects.GitLabId,
@JsonKey("project.path") projectPath: projects.Path,
status: EventStatus
)
object ProjectEvent {
implicit val jsonDecoder: Decoder[ProjectEvent] = deriveDecoder
}

def apply()(implicit logger: Logger[IO]): EventLogClient = new EventLogClient

Expand All @@ -138,6 +150,19 @@ object EventLogClient {
} yield ()
}.unsafeRunSync()

def getEvents(project: Either[projects.GitLabId, projects.Path]): IO[List[ProjectEvent]] =
for {
uri <- validateUri(s"$baseUrl/events").map(uri =>
project.fold(id => uri.withQueryParam("project-id", id.value),
path => uri.withQueryParam("project-path", path.value)
)
)
req = request(Method.GET, uri)
r <- send(req) { case (Status.Ok, _, resp) =>
resp.as[List[ProjectEvent]]
}
} yield r

private def createRequest(uri: Uri, event: Json) =
request(Method.POST, uri).withMultipartBuilder
.addPart("event", event)
Expand Down

0 comments on commit b5d1129

Please sign in to comment.