Changing how cron fetches available reservations to schedule
This commit is contained in:
parent
931a8b7f6c
commit
1da322ed05
2 changed files with 16 additions and 4 deletions
|
|
@ -3,7 +3,6 @@ import { Inject, Injectable } from '@nestjs/common'
|
||||||
import { Cron, CronExpression } from '@nestjs/schedule'
|
import { Cron, CronExpression } from '@nestjs/schedule'
|
||||||
import { Queue } from 'bull'
|
import { Queue } from 'bull'
|
||||||
|
|
||||||
import dayjs from '../common/dayjs'
|
|
||||||
import { LoggerService } from '../logger/service.logger'
|
import { LoggerService } from '../logger/service.logger'
|
||||||
import { RESERVATIONS_QUEUE_NAME } from './config'
|
import { RESERVATIONS_QUEUE_NAME } from './config'
|
||||||
import { ReservationsService } from './service'
|
import { ReservationsService } from './service'
|
||||||
|
|
@ -27,9 +26,8 @@ export class ReservationsCronService {
|
||||||
})
|
})
|
||||||
async handleDailyReservations() {
|
async handleDailyReservations() {
|
||||||
this.loggerService.log('handleDailyReservations beginning')
|
this.loggerService.log('handleDailyReservations beginning')
|
||||||
const reservationsToPerform = await this.reservationService.getByDate(
|
const reservationsToPerform =
|
||||||
dayjs().subtract(7, 'days'),
|
await this.reservationService.getScheduleable()
|
||||||
)
|
|
||||||
this.loggerService.log(
|
this.loggerService.log(
|
||||||
`Found ${reservationsToPerform.length} reservations to perform`,
|
`Found ${reservationsToPerform.length} reservations to perform`,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,20 @@ export class ReservationsService {
|
||||||
.getMany()
|
.getMany()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets all reservations that have not been scheduled that are within the reservation window
|
||||||
|
* @returns Reservations that can be scheduled
|
||||||
|
*/
|
||||||
|
async getScheduleable() {
|
||||||
|
return await this.reservationsRepository
|
||||||
|
.createQueryBuilder()
|
||||||
|
.where(`DATE(dateRangeStart) <= DATE(:date)`, {
|
||||||
|
date: dayjs().add(7, 'days'),
|
||||||
|
})
|
||||||
|
.andWhere(`waitListed = false`)
|
||||||
|
.getMany()
|
||||||
|
}
|
||||||
|
|
||||||
async getByDateOnWaitingList(date = dayjs()) {
|
async getByDateOnWaitingList(date = dayjs()) {
|
||||||
return await this.reservationsRepository
|
return await this.reservationsRepository
|
||||||
.createQueryBuilder()
|
.createQueryBuilder()
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue