stopping reservation of dangerous (<5hr until start) reservations

This commit is contained in:
Collin Duncan 2025-04-29 10:40:14 +02:00 committed by collin
parent 736e1f4d39
commit bedd062aa0
No known key found for this signature in database

View file

@ -12,6 +12,7 @@ import {
RESERVATIONS_QUEUE_NAME, RESERVATIONS_QUEUE_NAME,
ReservationsQueue, ReservationsQueue,
} from '../reservations/config' } from '../reservations/config'
import { Reservation } from '../reservations/entity'
import { ReservationsService } from '../reservations/service' import { ReservationsService } from '../reservations/service'
import { WaitingListDetails } from './types' import { WaitingListDetails } from './types'
@ -90,12 +91,25 @@ export class WaitingListService {
return return
} }
// don't book something within the ~~danger zone~~
const now = dayjs()
const { safe, dangerous } = reservations.reduce<{
safe: Reservation[]
dangerous: Reservation[]
}>(
(acc, res) =>
now.diff(res.dateRangeStart, 'hours') > 5
? { safe: [...acc.safe, res], dangerous: acc.dangerous }
: { safe: acc.safe, dangerous: [...acc.dangerous, res] },
{ safe: [], dangerous: [] },
)
this.loggerService.debug( this.loggerService.debug(
`Found ${reservations.length} reservations on waiting list`, `Found ${safe.length} safe reservations on waiting list (${dangerous.length} dangerous)`,
) )
await this.reservationsQueue.addBulk( await this.reservationsQueue.addBulk(
reservations.map((r) => ({ safe.map((r) => ({
data: { reservation: r, speedyMode: false }, data: { reservation: r, speedyMode: false },
opts: { attempts: 1 }, opts: { attempts: 1 },
})), })),