Making screenshots on error only happen in non-time sensitive flows and switching back to using a queue
This commit is contained in:
parent
00ffff7d6a
commit
d23358e5d8
3 changed files with 30 additions and 17 deletions
|
|
@ -71,15 +71,12 @@ export class ReservationsCronService {
|
|||
)
|
||||
|
||||
this.loggerService.debug(`It's go-time`)
|
||||
|
||||
for (const res of reservationsToPerform) {
|
||||
await this.brService.performReservation(res).catch(
|
||||
async () =>
|
||||
await this.reservationsQueue.add(res, {
|
||||
attempts: Math.max(DAILY_RESERVATIONS_ATTEMPTS - 1, 1),
|
||||
}),
|
||||
await this.reservationsQueue.addBulk(
|
||||
reservationsToPerform.map((res) => ({
|
||||
data: res,
|
||||
opts: { attempts: DAILY_RESERVATIONS_ATTEMPTS },
|
||||
})),
|
||||
)
|
||||
}
|
||||
} else {
|
||||
this.loggerService.debug('Monitoring reservations')
|
||||
await this.brService.monitorCourtReservations(dayjs().add(7, 'day'))
|
||||
|
|
|
|||
|
|
@ -43,13 +43,14 @@ export class ReservationsWorker {
|
|||
reservation.dateRangeStart,
|
||||
reservation.dateRangeEnd,
|
||||
)
|
||||
await this.performReservation(reservation, job.attemptsMade)
|
||||
await this.performReservation(reservation, job.attemptsMade, false)
|
||||
}
|
||||
|
||||
private async handleReservationErrors(
|
||||
error: Error,
|
||||
reservation: Reservation,
|
||||
attemptsMade: number,
|
||||
timeSensitive = true,
|
||||
) {
|
||||
const shouldWaitlist = error instanceof NoCourtAvailableError
|
||||
if (shouldWaitlist) {
|
||||
|
|
@ -67,13 +68,17 @@ export class ReservationsWorker {
|
|||
reservation.dateRangeStart,
|
||||
reservation.dateRangeEnd,
|
||||
)
|
||||
await this.addReservationToWaitList(reservation)
|
||||
await this.addReservationToWaitList(reservation, timeSensitive)
|
||||
} else {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
async performReservation(reservation: Reservation, attemptsMade: number) {
|
||||
async performReservation(
|
||||
reservation: Reservation,
|
||||
attemptsMade: number,
|
||||
timeSensitive = true,
|
||||
) {
|
||||
try {
|
||||
await this.brService.performReservation(reservation)
|
||||
await this.reservationsService.deleteById(reservation.id)
|
||||
|
|
@ -82,14 +87,19 @@ export class ReservationsWorker {
|
|||
error as Error,
|
||||
reservation,
|
||||
attemptsMade,
|
||||
timeSensitive,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
async addReservationToWaitList(reservation: Reservation) {
|
||||
async addReservationToWaitList(
|
||||
reservation: Reservation,
|
||||
timeSensitive = true,
|
||||
) {
|
||||
try {
|
||||
const waitingListId = await this.brService.addReservationToWaitList(
|
||||
reservation,
|
||||
timeSensitive,
|
||||
)
|
||||
await this.reservationsService.update(reservation.id, {
|
||||
waitListed: true,
|
||||
|
|
|
|||
|
|
@ -565,7 +565,10 @@ export class BaanReserverenService {
|
|||
return courtStatuses
|
||||
}
|
||||
|
||||
public async performReservation(reservation: Reservation) {
|
||||
public async performReservation(
|
||||
reservation: Reservation,
|
||||
timeSensitive = true,
|
||||
) {
|
||||
try {
|
||||
await this.init()
|
||||
await this.navigateToDay(reservation.dateRangeStart)
|
||||
|
|
@ -575,12 +578,15 @@ export class BaanReserverenService {
|
|||
await this.selectOpponents(reservation.opponents)
|
||||
await this.confirmReservation()
|
||||
} catch (error: unknown) {
|
||||
await this.handleError()
|
||||
if (!timeSensitive) await this.handleError()
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
public async addReservationToWaitList(reservation: Reservation) {
|
||||
public async addReservationToWaitList(
|
||||
reservation: Reservation,
|
||||
timeSensitive = true,
|
||||
) {
|
||||
try {
|
||||
await this.init()
|
||||
await this.navigateToWaitingList()
|
||||
|
|
@ -603,7 +609,7 @@ export class BaanReserverenService {
|
|||
|
||||
return waitingListId
|
||||
} catch (error: unknown) {
|
||||
await this.handleError()
|
||||
if (!timeSensitive) await this.handleError()
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue