Adding some custom errors for waiting list flow and changing number of attempts to 1 for all jobs for now
This commit is contained in:
parent
7002b44936
commit
714b1da735
4 changed files with 88 additions and 29 deletions
|
|
@ -33,7 +33,7 @@ export class ReservationsCronService {
|
||||||
`Found ${reservationsToPerform.length} reservations to perform`,
|
`Found ${reservationsToPerform.length} reservations to perform`,
|
||||||
)
|
)
|
||||||
await this.reservationsQueue.addBulk(
|
await this.reservationsQueue.addBulk(
|
||||||
reservationsToPerform.map((r) => ({ data: r })),
|
reservationsToPerform.map((r) => ({ data: r, opts: { attempts: 1 } })),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -67,7 +67,15 @@ export class ReservationsWorker {
|
||||||
}
|
}
|
||||||
|
|
||||||
async addReservationToWaitList(reservation: Reservation) {
|
async addReservationToWaitList(reservation: Reservation) {
|
||||||
await this.brService.addReservationToWaitList(reservation)
|
try {
|
||||||
await this.reservationsService.update(reservation.id, { waitListed: true })
|
await this.brService.addReservationToWaitList(reservation)
|
||||||
|
await this.reservationsService.update(reservation.id, {
|
||||||
|
waitListed: true,
|
||||||
|
})
|
||||||
|
} catch (error: unknown) {
|
||||||
|
this.loggerService.error('Error adding reservation to waiting list', {
|
||||||
|
error,
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ import dayjs from '../../common/dayjs'
|
||||||
import { Reservation } from '../../reservations/entity'
|
import { Reservation } from '../../reservations/entity'
|
||||||
import { EmptyPage } from '../pages/empty'
|
import { EmptyPage } from '../pages/empty'
|
||||||
|
|
||||||
const baanReserverenRoot = 'https://squashcity.baanreserveren.nl'
|
const BAAN_RESERVEREN_ROOT_URL = 'https://squashcity.baanreserveren.nl'
|
||||||
|
|
||||||
export enum BaanReserverenUrls {
|
export enum BaanReserverenUrls {
|
||||||
Reservations = '/reservations',
|
Reservations = '/reservations',
|
||||||
|
|
@ -51,12 +51,18 @@ export class BaanReserverenService {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private checkSession(username: string) {
|
private async checkSession(username: string) {
|
||||||
this.loggerService.debug('Checking session', {
|
this.loggerService.debug('Checking session', {
|
||||||
username,
|
username,
|
||||||
session: this.session,
|
session: this.session,
|
||||||
})
|
})
|
||||||
if (this.page.url().endsWith(BaanReserverenUrls.Reservations)) {
|
if (this.page.url().includes(BAAN_RESERVEREN_ROOT_URL)) {
|
||||||
|
// Check session via reload to see if we are still logged in via cookies
|
||||||
|
await this.page.reload()
|
||||||
|
if (this.page.url().includes('?reason=LOGGED_IN')) {
|
||||||
|
return SessionAction.Login
|
||||||
|
}
|
||||||
|
|
||||||
return this.session?.username !== username
|
return this.session?.username !== username
|
||||||
? SessionAction.Logout
|
? SessionAction.Logout
|
||||||
: SessionAction.NoAction
|
: SessionAction.NoAction
|
||||||
|
|
@ -110,7 +116,9 @@ export class BaanReserverenService {
|
||||||
|
|
||||||
private async logout() {
|
private async logout() {
|
||||||
this.loggerService.debug('Logging out')
|
this.loggerService.debug('Logging out')
|
||||||
await this.page.goto(`${baanReserverenRoot}${BaanReserverenUrls.Logout}`)
|
await this.page.goto(
|
||||||
|
`${BAAN_RESERVEREN_ROOT_URL}${BaanReserverenUrls.Logout}`,
|
||||||
|
)
|
||||||
this.endSession()
|
this.endSession()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -118,8 +126,8 @@ export class BaanReserverenService {
|
||||||
this.loggerService.debug('Initializing', {
|
this.loggerService.debug('Initializing', {
|
||||||
reservation: instanceToPlain(reservation),
|
reservation: instanceToPlain(reservation),
|
||||||
})
|
})
|
||||||
await this.page.goto(baanReserverenRoot)
|
await this.page.goto(BAAN_RESERVEREN_ROOT_URL)
|
||||||
const action = this.checkSession(reservation.username)
|
const action = await this.checkSession(reservation.username)
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case SessionAction.Logout:
|
case SessionAction.Logout:
|
||||||
await this.logout()
|
await this.logout()
|
||||||
|
|
@ -185,14 +193,25 @@ export class BaanReserverenService {
|
||||||
}
|
}
|
||||||
|
|
||||||
private async navigateToWaitingList() {
|
private async navigateToWaitingList() {
|
||||||
await this.page.goto(
|
this.loggerService.debug('Navigating to waiting list')
|
||||||
`${baanReserverenRoot}${BaanReserverenUrls.WaitingList}`,
|
await this.page
|
||||||
)
|
.goto(`${BAAN_RESERVEREN_ROOT_URL}${BaanReserverenUrls.WaitingList}`)
|
||||||
|
.catch((e) => {
|
||||||
|
throw new RunnerWaitingListNavigationError(e)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
private async openWaitingListDialog() {
|
private async openWaitingListDialog() {
|
||||||
|
this.loggerService.debug('Opening waiting list dialog')
|
||||||
|
const menuButtons = await this.page.$x('//button[text()="Menu"]')
|
||||||
|
const menuButton = await menuButtons[0].$('button')
|
||||||
|
await menuButton?.click().catch((e) => {
|
||||||
|
throw new RunnerWaitingListNavigationMenuError(e)
|
||||||
|
})
|
||||||
const dialogLink = await this.page.$('a[href="/waitinglist/add"]')
|
const dialogLink = await this.page.$('a[href="/waitinglist/add"]')
|
||||||
await dialogLink?.click()
|
await dialogLink?.click().catch((e) => {
|
||||||
|
throw new RunnerWaitingListNavigationAddError(e)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
private async selectAvailableTime(reservation: Reservation) {
|
private async selectAvailableTime(reservation: Reservation) {
|
||||||
|
|
@ -263,33 +282,55 @@ export class BaanReserverenService {
|
||||||
}
|
}
|
||||||
|
|
||||||
private async inputWaitingListDetails(reservation: Reservation) {
|
private async inputWaitingListDetails(reservation: Reservation) {
|
||||||
|
this.loggerService.debug('Inputting waiting list details')
|
||||||
const startDateInput = await this.page?.$('input[name="start_date"]')
|
const startDateInput = await this.page?.$('input[name="start_date"]')
|
||||||
await startDateInput?.click({ count: 3, delay: 10 }) // Click 3 times to select all existing text
|
// Click 3 times to select all existing text
|
||||||
await startDateInput?.type(
|
await startDateInput?.click({ count: 3, delay: 10 }).catch((e) => {
|
||||||
reservation.dateRangeStart.format('DD-MM-YYYY'),
|
throw new RunnerWaitingListInputError(e)
|
||||||
{ delay: this.getTypingDelay() },
|
})
|
||||||
)
|
await startDateInput
|
||||||
|
?.type(reservation.dateRangeStart.format('DD-MM-YYYY'), {
|
||||||
|
delay: this.getTypingDelay(),
|
||||||
|
})
|
||||||
|
.catch((e) => {
|
||||||
|
throw new RunnerWaitingListInputError(e)
|
||||||
|
})
|
||||||
|
|
||||||
const endDateInput = await this.page?.$('input[name="end_date"]')
|
const endDateInput = await this.page?.$('input[name="end_date"]')
|
||||||
await endDateInput?.type(reservation.dateRangeEnd.format('DD-MM-YYYY'), {
|
await endDateInput
|
||||||
delay: this.getTypingDelay(),
|
?.type(reservation.dateRangeEnd.format('DD-MM-YYYY'), {
|
||||||
})
|
delay: this.getTypingDelay(),
|
||||||
|
})
|
||||||
|
.catch((e) => {
|
||||||
|
throw new RunnerWaitingListInputError(e)
|
||||||
|
})
|
||||||
|
|
||||||
const startTimeInput = await this.page?.$('input[name="start_time"]')
|
const startTimeInput = await this.page?.$('input[name="start_time"]')
|
||||||
startTimeInput?.type(reservation.dateRangeStart.format('HH:mm'), {
|
startTimeInput
|
||||||
delay: this.getTypingDelay(),
|
?.type(reservation.dateRangeStart.format('HH:mm'), {
|
||||||
})
|
delay: this.getTypingDelay(),
|
||||||
|
})
|
||||||
|
.catch((e) => {
|
||||||
|
throw new RunnerWaitingListInputError(e)
|
||||||
|
})
|
||||||
|
|
||||||
// Use the same time for start and end so that the waiting list only notifies for start time
|
// Use the same time for start and end so that the waiting list only notifies for start time
|
||||||
const endTimeInput = await this.page?.$('input[name="end_time"]')
|
const endTimeInput = await this.page?.$('input[name="end_time"]')
|
||||||
endTimeInput?.type(reservation.dateRangeStart.format('HH:mm'), {
|
endTimeInput
|
||||||
delay: this.getTypingDelay(),
|
?.type(reservation.dateRangeStart.format('HH:mm'), {
|
||||||
})
|
delay: this.getTypingDelay(),
|
||||||
|
})
|
||||||
|
.catch((e) => {
|
||||||
|
throw new RunnerWaitingListInputError(e)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
private async confirmWaitingListDetails() {
|
private async confirmWaitingListDetails() {
|
||||||
|
this.loggerService.debug('Confirming waiting list details')
|
||||||
const saveButton = await this.page?.$('input[type="submit"][value="Save"]')
|
const saveButton = await this.page?.$('input[type="submit"][value="Save"]')
|
||||||
await saveButton?.click()
|
await saveButton?.click().catch((e) => {
|
||||||
|
throw new RunnerWaitingListConfirmError(e)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
public async performReservation(reservation: Reservation) {
|
public async performReservation(reservation: Reservation) {
|
||||||
|
|
@ -332,6 +373,14 @@ export class RunnerNavigationMonthError extends RunnerError {}
|
||||||
export class RunnerNavigationDayError extends RunnerError {}
|
export class RunnerNavigationDayError extends RunnerError {}
|
||||||
export class RunnerNavigationSelectionError extends RunnerError {}
|
export class RunnerNavigationSelectionError extends RunnerError {}
|
||||||
|
|
||||||
|
export class RunnerWaitingListNavigationError extends RunnerError {}
|
||||||
|
export class RunnerWaitingListNavigationMenuError extends RunnerError {}
|
||||||
|
export class RunnerWaitingListNavigationAddError extends RunnerError {}
|
||||||
|
|
||||||
|
export class RunnerWaitingListInputError extends RunnerError {}
|
||||||
|
|
||||||
|
export class RunnerWaitingListConfirmError extends RunnerError {}
|
||||||
|
|
||||||
export class RunnerCourtSelectionError extends RunnerError {}
|
export class RunnerCourtSelectionError extends RunnerError {}
|
||||||
export class NoCourtAvailableError extends Error {}
|
export class NoCourtAvailableError extends Error {}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,9 @@ export class WaitingListService {
|
||||||
`Found ${reservations.length} reservations on waiting list`,
|
`Found ${reservations.length} reservations on waiting list`,
|
||||||
)
|
)
|
||||||
|
|
||||||
await this.reservationsQueue.addBulk(reservations.map((r) => ({ data: r })))
|
await this.reservationsQueue.addBulk(
|
||||||
|
reservations.map((r) => ({ data: r, opts: { attempts: 1 } })),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private getWaitingListDetails(email: Email): WaitingListDetails {
|
private getWaitingListDetails(email: Email): WaitingListDetails {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue