Skip to content

Commit

Permalink
Merge pull request #3257 from navikt/load-tiltakstyper
Browse files Browse the repository at this point in the history
Fjern paginering fra initialLoadTiltakstyper
  • Loading branch information
sndrem authored Feb 12, 2024
2 parents e7ab559 + 9ef09b2 commit a87e1e7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ class TiltakstypeRepository(private val db: Database) {
}

fun getAllMedDeltakerregistreringsinnhold(): List<TiltakstypeEksternDto> {
val tiltakstyper = getAll()
val tiltakstyper = getAll(paginationParams = PaginationParams(nullableLimit = 1000))

return tiltakstyper.second.map { tiltakstypeAdminDto ->
val deltakerRegistreringInnhold = getDeltakerregistreringInnholdByTiltakskode(tiltakstypeAdminDto.arenaKode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,8 @@ package no.nav.mulighetsrommet.api.tasks
import com.github.kagkarlsson.scheduler.SchedulerClient
import com.github.kagkarlsson.scheduler.task.helper.OneTimeTask
import com.github.kagkarlsson.scheduler.task.helper.Tasks
import kotlinx.coroutines.async
import kotlinx.coroutines.cancelAndJoin
import kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking
import no.nav.mulighetsrommet.api.repositories.TiltakstypeRepository
import no.nav.mulighetsrommet.api.utils.DatabaseUtils.paginateFanOut
import no.nav.mulighetsrommet.api.utils.PaginationParams
import no.nav.mulighetsrommet.database.Database
import no.nav.mulighetsrommet.kafka.producers.TiltakstypeKafkaProducer
import org.slf4j.LoggerFactory
Expand All @@ -25,30 +20,16 @@ class InitialLoadTiltakstyper(

private val logger = LoggerFactory.getLogger(javaClass)

val task: OneTimeTask<InitialLoadTiltaksgjennomforingerInput> = Tasks
.oneTime(javaClass.name, InitialLoadTiltaksgjennomforingerInput::class.java)
.execute { instance, context ->
val task: OneTimeTask<Void> = Tasks
.oneTime(javaClass.name)
.execute { instance, _ ->

logger.info("Running task ${instance.taskName}")

MDC.put("correlationId", instance.id)

runBlocking {
val job = async {
initialLoadTiltakstyper()
}

while (job.isActive) {
if (context.schedulerState.isShuttingDown) {
logger.info("Stopping task ${instance.taskName} due to shutdown signal")

job.cancelAndJoin()

logger.info("Task ${instance.taskName} stopped")
} else {
delay(1000)
}
}
initialLoadTiltakstyper()
}
}

Expand All @@ -63,14 +44,7 @@ class InitialLoadTiltakstyper(
return id
}

private suspend fun initialLoadTiltakstyper(): Int {
return paginateFanOut(
{ pagination: PaginationParams ->
logger.info("Henter tiltakstyper limit=${pagination.limit} offset=${pagination.offset}")
tiltakstyper.getAllMedDeltakerregistreringsinnhold()
},
) {
tiltakstypeProducer.publish(it)
}
private fun initialLoadTiltakstyper() {
tiltakstyper.getAllMedDeltakerregistreringsinnhold().forEach { tiltakstypeProducer.publish(it) }
}
}

0 comments on commit a87e1e7

Please sign in to comment.