Properly retrying speedy reservations and speeding up searching for opponents

This commit is contained in:
Collin Duncan 2024-05-07 11:47:44 +02:00
parent feb3c4b8d0
commit bfc72f2cfb
No known key found for this signature in database

View file

@ -558,16 +558,13 @@ export class BaanReserverenService {
.catch((e: Error) => { .catch((e: Error) => {
throw new RunnerOpponentSearchError(e) throw new RunnerOpponentSearchError(e)
}) })
await playerSearch await playerSearch?.type(name).catch((e: Error) => {
?.type(name, { delay: this.getTypingDelay() })
.catch((e: Error) => {
throw new RunnerOpponentSearchInputError(e) throw new RunnerOpponentSearchInputError(e)
}) })
await this.page.waitForNetworkIdle().catch((e: Error) => {
throw new RunnerOpponentSearchNetworkError(e)
})
await this.page await this.page
.$(`select.br-user-select[name="players[${resolvedIndex}]"]`) .waitForSelector(
`select.br-user-select[name="players[${resolvedIndex}]"]`,
)
.then((d) => d?.select(id)) .then((d) => d?.select(id))
.catch((e: Error) => { .catch((e: Error) => {
throw new RunnerOpponentSearchSelectionError(e) throw new RunnerOpponentSearchSelectionError(e)
@ -716,14 +713,16 @@ export class BaanReserverenService {
) )
await this.selectOwner(reservation.ownerId) await this.selectOwner(reservation.ownerId)
await this.selectOpponents(reservation.opponents) await this.selectOpponents(reservation.opponents)
let errorReserving = false
await this.confirmReservation().catch((error: Error) => { await this.confirmReservation().catch((error: Error) => {
if (error instanceof RunnerReservationConfirmSubmitError) { if (error instanceof RunnerReservationConfirmSubmitError) {
this.loggerService.warn('Court taken, retrying', { courtSlot }) this.loggerService.warn('Court taken, retrying', { courtSlot })
return errorReserving = true
} } else {
throw error throw error
}
}) })
return if (!errorReserving) return
} }
throw new NoCourtAvailableError('Could not reserve court') throw new NoCourtAvailableError('Could not reserve court')