Making screenshots on error only happen in non-time sensitive flows and switching back to using a queue

This commit is contained in:
Collin Duncan 2024-04-11 11:46:25 +02:00
parent 00ffff7d6a
commit d23358e5d8
No known key found for this signature in database
3 changed files with 30 additions and 17 deletions

View file

@ -71,15 +71,12 @@ export class ReservationsCronService {
) )
this.loggerService.debug(`It's go-time`) this.loggerService.debug(`It's go-time`)
await this.reservationsQueue.addBulk(
for (const res of reservationsToPerform) { reservationsToPerform.map((res) => ({
await this.brService.performReservation(res).catch( data: res,
async () => opts: { attempts: DAILY_RESERVATIONS_ATTEMPTS },
await this.reservationsQueue.add(res, { })),
attempts: Math.max(DAILY_RESERVATIONS_ATTEMPTS - 1, 1),
}),
) )
}
} else { } else {
this.loggerService.debug('Monitoring reservations') this.loggerService.debug('Monitoring reservations')
await this.brService.monitorCourtReservations(dayjs().add(7, 'day')) await this.brService.monitorCourtReservations(dayjs().add(7, 'day'))

View file

@ -43,13 +43,14 @@ export class ReservationsWorker {
reservation.dateRangeStart, reservation.dateRangeStart,
reservation.dateRangeEnd, reservation.dateRangeEnd,
) )
await this.performReservation(reservation, job.attemptsMade) await this.performReservation(reservation, job.attemptsMade, false)
} }
private async handleReservationErrors( private async handleReservationErrors(
error: Error, error: Error,
reservation: Reservation, reservation: Reservation,
attemptsMade: number, attemptsMade: number,
timeSensitive = true,
) { ) {
const shouldWaitlist = error instanceof NoCourtAvailableError const shouldWaitlist = error instanceof NoCourtAvailableError
if (shouldWaitlist) { if (shouldWaitlist) {
@ -67,13 +68,17 @@ export class ReservationsWorker {
reservation.dateRangeStart, reservation.dateRangeStart,
reservation.dateRangeEnd, reservation.dateRangeEnd,
) )
await this.addReservationToWaitList(reservation) await this.addReservationToWaitList(reservation, timeSensitive)
} else { } else {
throw error throw error
} }
} }
async performReservation(reservation: Reservation, attemptsMade: number) { async performReservation(
reservation: Reservation,
attemptsMade: number,
timeSensitive = true,
) {
try { try {
await this.brService.performReservation(reservation) await this.brService.performReservation(reservation)
await this.reservationsService.deleteById(reservation.id) await this.reservationsService.deleteById(reservation.id)
@ -82,14 +87,19 @@ export class ReservationsWorker {
error as Error, error as Error,
reservation, reservation,
attemptsMade, attemptsMade,
timeSensitive,
) )
} }
} }
async addReservationToWaitList(reservation: Reservation) { async addReservationToWaitList(
reservation: Reservation,
timeSensitive = true,
) {
try { try {
const waitingListId = await this.brService.addReservationToWaitList( const waitingListId = await this.brService.addReservationToWaitList(
reservation, reservation,
timeSensitive,
) )
await this.reservationsService.update(reservation.id, { await this.reservationsService.update(reservation.id, {
waitListed: true, waitListed: true,

View file

@ -565,7 +565,10 @@ export class BaanReserverenService {
return courtStatuses return courtStatuses
} }
public async performReservation(reservation: Reservation) { public async performReservation(
reservation: Reservation,
timeSensitive = true,
) {
try { try {
await this.init() await this.init()
await this.navigateToDay(reservation.dateRangeStart) await this.navigateToDay(reservation.dateRangeStart)
@ -575,12 +578,15 @@ export class BaanReserverenService {
await this.selectOpponents(reservation.opponents) await this.selectOpponents(reservation.opponents)
await this.confirmReservation() await this.confirmReservation()
} catch (error: unknown) { } catch (error: unknown) {
await this.handleError() if (!timeSensitive) await this.handleError()
throw error throw error
} }
} }
public async addReservationToWaitList(reservation: Reservation) { public async addReservationToWaitList(
reservation: Reservation,
timeSensitive = true,
) {
try { try {
await this.init() await this.init()
await this.navigateToWaitingList() await this.navigateToWaitingList()
@ -603,7 +609,7 @@ export class BaanReserverenService {
return waitingListId return waitingListId
} catch (error: unknown) { } catch (error: unknown) {
await this.handleError() if (!timeSensitive) await this.handleError()
throw error throw error
} }
} }