Skip to content

Commit 7192146

Browse files
committed
limit number of uploaded check-ins in order to keep the size small
1 parent d8dcac2 commit 7192146

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

backend/src/main/kotlin/alfio/pi/manager/CheckInManager.kt

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -340,12 +340,12 @@ open class CheckInDataManager(@Qualifier("masterConnectionConfiguration") privat
340340
})
341341
}
342342

343-
@Scheduled(fixedDelay = 15000L)
343+
@Scheduled(fixedDelay = 1500L)
344344
open fun processPendingEntries() {
345345
if(kvStore.isLeader()) {
346-
val failures = kvStore.findRemoteFailures()
347-
logger.trace("found ${failures.size} pending scan to upload")
348-
failures
346+
val pending = kvStore.findCheckInToUpload()
347+
logger.trace("found ${pending.size} pending scan to upload")
348+
pending
349349
.groupBy { it.eventKey }
350350
.mapKeys { eventRepository.loadSingle(it.key) }
351351
.filter { it.key.isPresent }
@@ -354,18 +354,18 @@ open class CheckInDataManager(@Qualifier("masterConnectionConfiguration") privat
354354
}
355355

356356
private fun uploadEntriesForEvent(entry: Map.Entry<Optional<Event>, List<ScanLog>>) {
357-
logger.info("******** uploading check-in **********")
357+
logger.info("******** uploading check-in for event ${entry.key.get().key} (${entry.value.size}) **********")
358358
tryOrDefault<Unit>().invoke({
359359
val event = entry.key.get()
360-
val scanLogEntries = entry.value.filter { it.ticket != null }
361-
val ticketIdToScanLogId = scanLogEntries.associate { it.ticket!!.uuid to it.id }
362-
val response = remoteCheckInExecutor.remoteBulkCheckIn(event.key, scanLogEntries) { list -> list.map { mapOf("identifier" to it.ticket!!.uuid, "code" to "${it.ticket.uuid}/${it.ticket.hmac}")}}
363-
364-
response.forEach {
365-
if(logger.isTraceEnabled) {
366-
logger.trace("upload entries response is ${it.key} ${gson.toJson(it.value)}")
360+
entry.value.filter { it.ticket != null }.chunked(200).forEach { scanLogEntries ->
361+
val ticketIdToScanLogId = scanLogEntries.associate { it.ticket!!.uuid to it.id }
362+
val response = remoteCheckInExecutor.remoteBulkCheckIn(event.key, scanLogEntries) { list -> list.map { mapOf("identifier" to it.ticket!!.uuid, "code" to "${it.ticket.uuid}/${it.ticket.hmac}")}}
363+
response.forEach {
364+
if(logger.isTraceEnabled) {
365+
logger.trace("upload entries response is ${it.key} ${gson.toJson(it.value)}")
366+
}
367+
kvStore.updateRemoteResult(it.value.result.status, ticketIdToScanLogId[it.key] ?: error("Unexpected error during check-in upload"))
367368
}
368-
kvStore.updateRemoteResult(it.value.result.status, ticketIdToScanLogId[it.key] ?: error("Unexpected error during check-in upload"))
369369
}
370370
}, { logger.error("unable to upload pending check-in", it)})
371371
logger.info("******** upload completed **********")

backend/src/main/kotlin/alfio/pi/manager/KVStore.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ open class KVStore(private val gson: Gson) {
202202
val key = scanLogId()
203203
val scanLogWithKey = ScanLogToPersist(key, timestamp.toInstant().toEpochMilli(), timestamp.zone.id, eventKey, uuid, userId,
204204
localResult, remoteResult, badgePrinted, jsonPayload)
205-
putScanLong(scanLogWithKey)
205+
putScanLog(scanLogWithKey)
206206
}
207207

208208
open fun insertBadgeScan(eventKey: String, badgeScan: BadgeScan) =
@@ -224,7 +224,7 @@ open class KVStore(private val gson: Gson) {
224224
.limit(100)
225225
.collect(Collectors.toList())
226226

227-
private fun putScanLong(scanLog: ScanLogToPersist) {
227+
private fun putScanLog(scanLog: ScanLogToPersist) {
228228
scanLogTable.put(scanLog.id, scanLog)
229229
scanLogForEventTicket.put(scanLog.eventKey + "_" + scanLog.ticketUuid, scanLog.id)
230230
}
@@ -255,7 +255,7 @@ open class KVStore(private val gson: Gson) {
255255
return findOptionalById(key).filter { scanLog -> scanLog.eventKey == eventKey }
256256
}
257257

258-
open fun findRemoteFailures(): List<ScanLog> {
258+
open fun findCheckInToUpload(): List<ScanLog> {
259259
return scanLogTable.stream()
260260
.filter{ it.value.remoteResult == CheckInStatus.RETRY}
261261
.map { it.value.toScanLog() }
@@ -273,7 +273,7 @@ open class KVStore(private val gson: Gson) {
273273
findOptionalById(key).ifPresent { scanLog ->
274274
val updatedScanLog = ScanLogToPersist(scanLog.id, scanLog.timestamp.toInstant().toEpochMilli(), scanLog.timestamp.zone.id, scanLog.eventKey, scanLog.ticketUuid,
275275
scanLog.userId, scanLog.localResult, remoteResult, scanLog.badgePrinted, scanLog.ticketData)
276-
putScanLong(updatedScanLog)
276+
putScanLog(updatedScanLog)
277277
}
278278
}
279279

backend/src/main/kotlin/alfio/pi/manager/RemoteCheckInExecutor.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ open class RemoteCheckInExecutor(private val gson: Gson,
5757
.url(url)
5858
.build()
5959
logger.debug("Will call remote url {}", url)
60-
httpClientWithCustomTimeout(100L to TimeUnit.MILLISECONDS, 1L to TimeUnit.SECONDS)
60+
httpClientWithCustomTimeout(1L to TimeUnit.SECONDS, 10L to TimeUnit.SECONDS)
6161
.invoke(httpClient)
6262
.newCall(request)
6363
.execute()

0 commit comments

Comments
 (0)