Implementing multiple attempts or failing early if courts are full

This commit is contained in:
Collin Duncan 2024-03-20 20:43:37 +01:00
parent c1199b9ec9
commit 3a88831148
No known key found for this signature in database

View file

@ -51,12 +51,14 @@ export class ReservationsWorker {
reservation: Reservation,
attemptsMade: number,
) {
if (error instanceof NoCourtAvailableError) {
const shouldWaitlist = error instanceof NoCourtAvailableError
if (shouldWaitlist) {
this.loggerService.warn('No court available')
} else {
this.loggerService.error('Error while performing reservation', error)
}
this.loggerService.error('Error while performing reservation', error)
if (
attemptsMade === DAILY_RESERVATIONS_ATTEMPTS &&
(shouldWaitlist || attemptsMade === DAILY_RESERVATIONS_ATTEMPTS) &&
!reservation.waitListed
) {
this.loggerService.log('Adding reservation to waiting list')
@ -66,6 +68,8 @@ export class ReservationsWorker {
reservation.dateRangeEnd,
)
await this.brService.addReservationToWaitList(reservation)
} else {
throw error
}
}