Skip to content

Commit

Permalink
Ensure Cache manifest for new PlanLimit queries is periodically updated
Browse files Browse the repository at this point in the history
  • Loading branch information
vimto committed Sep 12, 2023
1 parent b940f73 commit 564a05a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package nz.govt.eop.plan_limits
import java.math.BigInteger
import java.security.MessageDigest
import java.time.Instant
import org.jooq.DSLContext
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.cache.annotation.CachePut
import org.springframework.cache.annotation.Cacheable
Expand All @@ -11,13 +12,23 @@ import org.springframework.stereotype.Component
const val MANIFEST_CACHE_KEY = "QUERY_MANIFEST"

@Component
class Manifest(@Autowired val queries: Queries) {
class Manifest(@Autowired val queries: Queries, val context: DSLContext) {

@Cacheable(cacheNames = [MANIFEST_CACHE_KEY])
fun get(councilId: Int): Map<String, String> {
return generate(councilId)
}

fun updateAll() {
// Hard coded to just Wellington until we have more data since empty results
// for individual queries cause errors
update(9)

// val councils = context.selectFrom(COUNCILS).fetch()
// for (council in councils) {
// update(council.id!!)
// }
}
@CachePut(cacheNames = [MANIFEST_CACHE_KEY])
fun update(councilId: Int): Map<String, String> {
return generate(councilId)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package nz.govt.eop.tasks

import java.util.concurrent.TimeUnit
import mu.KotlinLogging
import net.javacrumbs.shedlock.spring.annotation.SchedulerLock
import nz.govt.eop.plan_limits.Manifest
import org.jooq.DSLContext
import org.springframework.scheduling.annotation.Scheduled
import org.springframework.stereotype.Component

@Component
class PlanLimitsManifestUpdater(val context: DSLContext, val manifest: Manifest) {

private val logger = KotlinLogging.logger {}
@Scheduled(fixedDelay = 1, timeUnit = TimeUnit.MINUTES)
@SchedulerLock(name = "planLimitsManifestUpdater")
fun updateManifest() {
logger.debug { startTaskMessage("planLimitsManifestUpdater") }
manifest.updateAll()
logger.debug { endTaskMessage("planLimitsManifestUpdater") }
}
}

0 comments on commit 564a05a

Please sign in to comment.