Skip to content

Commit

Permalink
OK-736 Separate function, make poll wait configurable, improve test
Browse files Browse the repository at this point in the history
  • Loading branch information
msiukola committed Jan 10, 2025
1 parent c151f3e commit 9d2d22b
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -395,20 +395,24 @@ class KoskiService(
saveSuoritusBatchWithRetries(retries)
}

private def callKoskiToCreateMassaluovutusQuery(queryParams: KoskiMassaluovutusQueryParams): Future[KoskiMassaluovutusQueryResponse] = {
virkailijaRestClient
.postObjectWithCodes[KoskiMassaluovutusQueryParams, KoskiMassaluovutusQueryResponse](
"koski.sure.massaluovutus.create-query",
Seq(200),
maxRetries = 2,
resource = queryParams,
basicAuth = true
)
}

private def createAndHandleKoskiMassaluovutusQuery(
koskiQuery: KoskiMassaluovutusQueryParams,
params: KoskiSuoritusTallennusParams
): Future[KoskiProcessingResults] = {
try {
logger.info(s"Kutsutaan Kosken massaluovutusrajapintaa: $koskiQuery")
val resultF = virkailijaRestClient
.postObjectWithCodes[KoskiMassaluovutusQueryParams, KoskiMassaluovutusQueryResponse](
"koski.sure.massaluovutus.create-query",
Seq(200),
maxRetries = 2,
resource = koskiQuery,
basicAuth = true
)
val resultF = callKoskiToCreateMassaluovutusQuery(koskiQuery)
.flatMap((baseQueryResponse: KoskiMassaluovutusQueryResponse) => {
logger.info(
s"Saatiin vastaus massaluovutusrajapinnalta: ${baseQueryResponse
Expand Down Expand Up @@ -473,7 +477,7 @@ class KoskiService(
logger.info(
s"Pollataan lisää piakkoin! Koskessa valmiina ${previousPollResult.map(_.files).getOrElse(Seq.empty).size}"
)
Thread.sleep(5000)
Thread.sleep(params.massaluovutusPollWaitMillis)
pollMassaluovutus(resultsUrl)
}
pollResultF.flatMap(massaluovutusQueryResponse => {
Expand Down Expand Up @@ -578,7 +582,7 @@ class KoskiService(
Future.successful(KoskiProcessingResults(Set[String](), Set[String]()))
) { case (accFuture, (oidBatch, batchNr)) =>
accFuture.flatMap(accResult => {
logger.info(s"Käsitellään erä ${batchNr + 1}/${groupedOids.size + 1}")
logger.info(s"Käsitellään erä ${batchNr + 1}/${groupedOids.size}")
createAndHandleKoskiMassaluovutusQuery(
KoskiMassaluovutusQueryParams(
"sure-oppijat",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,5 +379,6 @@ case class KoskiSuoritusTallennusParams(
saveLukio: Boolean = false,
saveAmmatillinen: Boolean = false,
saveSeiskaKasiJaValmistava: Boolean = false,
retryWaitMillis: Long = 10000
retryWaitMillis: Long = 10000,
massaluovutusPollWaitMillis: Long = 2500
)

Large diffs are not rendered by default.

0 comments on commit 9d2d22b

Please sign in to comment.