Skip to content

Commit

Permalink
Handle timeouts more gracefully in OrderService
Browse files Browse the repository at this point in the history
  • Loading branch information
anotheroneofthese committed Aug 16, 2024
1 parent f5c8a5e commit f5bd98a
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions src/main/kotlin/no/nb/mlt/wls/order/service/OrderService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,27 @@ class OrderService(val db: OrderRepository, val synqService: SynqOrderService) {
return ResponseEntity.badRequest().build()
}

try {
// TODO - Usages?
val synqResponse = synqService.createOrder(payload.toOrder().toSynqPayload())
// Return what the database saved, as it could contain changes
val order =
db.save(payload.toOrder())
.timeout(Duration.ofSeconds(6))
.awaitSingle()
return ResponseEntity.status(HttpStatus.CREATED).body(order.toApiOrderPayload())
} catch (e: Exception) {
throw ServerErrorException("Failed to create order in storage system", e)
}
synqService.createOrder(payload.toOrder().toSynqPayload())
// Return what the database saved, as it could contain changes
val order =
db.save(payload.toOrder())
.timeout(Duration.ofSeconds(6))
.onErrorMap(TimeoutException::class.java) {
logger.error { "Saving order timed out for payload: %s".format(payload.toString()) }
ServerErrorException("Failed to create the order in storage system", it)
}
.awaitSingle()

return ResponseEntity.status(HttpStatus.CREATED).body(order.toApiOrderPayload())
}

suspend fun getByHostNameAndHostOrderId(payload: ApiOrderPayload): Order? {
// TODO - See if timeouts can be made configurable
return db.getByHostNameAndHostOrderId(payload.hostName, payload.orderId)
.timeout(Duration.ofSeconds(8))
.doOnError {
if (it is TimeoutException) {
logger.error(it, { "Timed out while fetching from WLS database" })
.doOnError(TimeoutException::class.java) {
logger.error(it) {
"Timed out while fetching from WLS database. Relevant payload: $payload"
}
}
.onErrorComplete(TimeoutException::class.java)
Expand Down

0 comments on commit f5bd98a

Please sign in to comment.