Revert "Removing monitor and screenshotting from flow for now"
This reverts commit c7e500ad6f.
This commit is contained in:
parent
6340a2328e
commit
c09532f89a
2 changed files with 38 additions and 6 deletions
|
|
@ -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,
|
||||||
|
|
|
||||||
|
|
@ -116,6 +116,18 @@ export class BaanReserverenService {
|
||||||
return TYPING_DELAY_MS
|
return TYPING_DELAY_MS
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async handleError() {
|
||||||
|
await this.page
|
||||||
|
.screenshot({
|
||||||
|
type: 'jpeg',
|
||||||
|
path: `./${Date.now()}_error-screenshot.jpeg`,
|
||||||
|
quality: 50,
|
||||||
|
})
|
||||||
|
.catch((reason: any) =>
|
||||||
|
this.loggerService.warn('Failed to take screenshot', { reason }),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
// Check session by going to /reservations to see if we are still logged in via cookies
|
// Check session by going to /reservations to see if we are still logged in via cookies
|
||||||
private async checkSession(username: string) {
|
private async checkSession(username: string) {
|
||||||
this.loggerService.debug('Checking session', {
|
this.loggerService.debug('Checking session', {
|
||||||
|
|
@ -553,20 +565,28 @@ 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)
|
||||||
|
await this.monitorCourtReservations()
|
||||||
await this.selectAvailableTime(reservation)
|
await this.selectAvailableTime(reservation)
|
||||||
await this.selectOwner(reservation.ownerId)
|
await this.selectOwner(reservation.ownerId)
|
||||||
await this.selectOpponents(reservation.opponents)
|
await this.selectOpponents(reservation.opponents)
|
||||||
await this.confirmReservation()
|
await this.confirmReservation()
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
|
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()
|
||||||
|
|
@ -589,6 +609,7 @@ export class BaanReserverenService {
|
||||||
|
|
||||||
return waitingListId
|
return waitingListId
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
|
if (!timeSensitive) await this.handleError()
|
||||||
throw error
|
throw error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -600,6 +621,7 @@ export class BaanReserverenService {
|
||||||
await this.navigateToWaitingList()
|
await this.navigateToWaitingList()
|
||||||
await this.deleteWaitingListEntryRowById(reservation.waitingListId)
|
await this.deleteWaitingListEntryRowById(reservation.waitingListId)
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
|
await this.handleError()
|
||||||
throw error
|
throw error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue