Allowing monitoring of reservations even if no daily reservations are found and updating some types for better constraints
This commit is contained in:
parent
6d35307cd6
commit
90ddea4bb5
6 changed files with 54 additions and 19 deletions
|
|
@ -1 +1,7 @@
|
|||
import type { Queue } from 'bull'
|
||||
|
||||
import type { MonitoringQueueData } from './worker'
|
||||
|
||||
export const MONITORING_QUEUE_NAME = 'monitoring'
|
||||
|
||||
export type MonitoringQueue = Queue<MonitoringQueueData>
|
||||
|
|
|
|||
|
|
@ -1 +1,7 @@
|
|||
import type { Queue } from 'bull'
|
||||
|
||||
import type { Reservation } from './entity'
|
||||
|
||||
export const RESERVATIONS_QUEUE_NAME = 'reservations'
|
||||
|
||||
export type ReservationsQueue = Queue<Reservation>
|
||||
|
|
|
|||
|
|
@ -11,15 +11,13 @@ import {
|
|||
Query,
|
||||
UseInterceptors,
|
||||
} from '@nestjs/common'
|
||||
import { Queue } from 'bull'
|
||||
import { Transform, TransformationType } from 'class-transformer'
|
||||
import { IsBoolean, IsOptional, IsString } from 'class-validator'
|
||||
import { Dayjs } from 'dayjs'
|
||||
|
||||
import dayjs from '../common/dayjs'
|
||||
import { LoggerService } from '../logger/service.logger'
|
||||
import { RESERVATIONS_QUEUE_NAME } from './config'
|
||||
import { Reservation } from './entity'
|
||||
import { RESERVATIONS_QUEUE_NAME, ReservationsQueue } from './config'
|
||||
import { ReservationsService } from './service'
|
||||
|
||||
export class GetReservationsQueryParams {
|
||||
|
|
@ -79,7 +77,7 @@ export class ReservationsController {
|
|||
private reservationsService: ReservationsService,
|
||||
|
||||
@InjectQueue(RESERVATIONS_QUEUE_NAME)
|
||||
private reservationsQueue: Queue<Reservation>,
|
||||
private reservationsQueue: ReservationsQueue,
|
||||
|
||||
@Inject(LoggerService)
|
||||
private loggerService: LoggerService,
|
||||
|
|
|
|||
|
|
@ -1,11 +1,14 @@
|
|||
import { InjectQueue } from '@nestjs/bull'
|
||||
import { Inject, Injectable } from '@nestjs/common'
|
||||
import { Cron, CronExpression } from '@nestjs/schedule'
|
||||
import { Queue } from 'bull'
|
||||
|
||||
import dayjs from '../common/dayjs'
|
||||
import { LoggerService } from '../logger/service.logger'
|
||||
import { MONITORING_QUEUE_NAME, MonitoringQueue } from '../monitoring/config'
|
||||
import { MonitorType } from '../monitoring/entity'
|
||||
import { NtfyProvider } from '../ntfy/provider'
|
||||
import { RESERVATIONS_QUEUE_NAME } from './config'
|
||||
import { BaanReserverenService } from '../runner/baanreserveren/service'
|
||||
import { RESERVATIONS_QUEUE_NAME, ReservationsQueue } from './config'
|
||||
import { ReservationsService } from './service'
|
||||
|
||||
export const DAILY_RESERVATIONS_ATTEMPTS = 2
|
||||
|
|
@ -16,8 +19,14 @@ export class ReservationsCronService {
|
|||
@Inject(ReservationsService)
|
||||
private readonly reservationService: ReservationsService,
|
||||
|
||||
@Inject(BaanReserverenService)
|
||||
private readonly brService: BaanReserverenService,
|
||||
|
||||
@InjectQueue(RESERVATIONS_QUEUE_NAME)
|
||||
private readonly reservationsQueue: Queue,
|
||||
private readonly reservationsQueue: ReservationsQueue,
|
||||
|
||||
@InjectQueue(MONITORING_QUEUE_NAME)
|
||||
private readonly monitoringQueue: MonitoringQueue,
|
||||
|
||||
@Inject(NtfyProvider)
|
||||
private readonly ntfyProvider: NtfyProvider,
|
||||
|
|
@ -34,15 +43,24 @@ export class ReservationsCronService {
|
|||
this.loggerService.log('handleDailyReservations beginning')
|
||||
await this.ntfyProvider.sendCronStartNotification('handleDailyReservations')
|
||||
const reservationsToPerform = await this.reservationService.getSchedulable()
|
||||
this.loggerService.log(
|
||||
`Found ${reservationsToPerform.length} reservations to perform`,
|
||||
)
|
||||
await this.reservationsQueue.addBulk(
|
||||
reservationsToPerform.map((r) => ({
|
||||
data: r,
|
||||
opts: { attempts: DAILY_RESERVATIONS_ATTEMPTS },
|
||||
})),
|
||||
)
|
||||
if (reservationsToPerform.length > 0) {
|
||||
this.loggerService.log(
|
||||
`Found ${reservationsToPerform.length} reservations to perform`,
|
||||
)
|
||||
await this.reservationsQueue.addBulk(
|
||||
reservationsToPerform.map((r) => ({
|
||||
data: r,
|
||||
opts: { attempts: DAILY_RESERVATIONS_ATTEMPTS },
|
||||
})),
|
||||
)
|
||||
} else {
|
||||
this.loggerService.log('Monitoring reservations')
|
||||
const monitorData = await this.brService.monitorCourtReservations(dayjs())
|
||||
await this.monitoringQueue.add({
|
||||
type: MonitorType.CourtReservations,
|
||||
data: monitorData,
|
||||
})
|
||||
}
|
||||
this.loggerService.log('handleDailyReservations ending')
|
||||
await this.ntfyProvider.sendCronStopNotification(
|
||||
'handleDailyReservations',
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@ import { Module } from '@nestjs/common'
|
|||
import { TypeOrmModule } from '@nestjs/typeorm'
|
||||
|
||||
import { LoggerModule } from '../logger/module'
|
||||
import { MONITORING_QUEUE_NAME } from '../monitoring/config'
|
||||
import { MonitoringModule } from '../monitoring/module'
|
||||
import { NtfyModule } from '../ntfy/module'
|
||||
import { RunnerModule } from '../runner/module'
|
||||
import { RESERVATIONS_QUEUE_NAME } from './config'
|
||||
|
|
@ -16,9 +18,11 @@ import { ReservationsWorker } from './worker'
|
|||
imports: [
|
||||
LoggerModule,
|
||||
TypeOrmModule.forFeature([Reservation]),
|
||||
BullModule.registerQueueAsync({ name: MONITORING_QUEUE_NAME }),
|
||||
BullModule.registerQueueAsync({ name: RESERVATIONS_QUEUE_NAME }),
|
||||
RunnerModule,
|
||||
NtfyModule,
|
||||
MonitoringModule,
|
||||
],
|
||||
exports: [ReservationsService],
|
||||
controllers: [ReservationsController],
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { InjectQueue, Process, Processor } from '@nestjs/bull'
|
||||
import { Inject, Injectable } from '@nestjs/common'
|
||||
import { Job, Queue } from 'bull'
|
||||
import { Job } from 'bull'
|
||||
|
||||
import dayjs from '../common/dayjs'
|
||||
import { EMAILS_QUEUE_NAME } from '../email/config'
|
||||
|
|
@ -8,7 +8,10 @@ import { EmailProvider } from '../email/provider'
|
|||
import { Email } from '../email/types'
|
||||
import { LoggerService } from '../logger/service.logger'
|
||||
import { NtfyProvider } from '../ntfy/provider'
|
||||
import { RESERVATIONS_QUEUE_NAME } from '../reservations/config'
|
||||
import {
|
||||
RESERVATIONS_QUEUE_NAME,
|
||||
ReservationsQueue,
|
||||
} from '../reservations/config'
|
||||
import { ReservationsService } from '../reservations/service'
|
||||
import { WaitingListDetails } from './types'
|
||||
|
||||
|
|
@ -29,7 +32,7 @@ const EMAIL_END_TIME_REGEX = new RegExp(/^Eindtijd: ([0-9]{1,2}:[0-9]{1,2})$/im)
|
|||
export class WaitingListService {
|
||||
constructor(
|
||||
@InjectQueue(RESERVATIONS_QUEUE_NAME)
|
||||
private readonly reservationsQueue: Queue,
|
||||
private readonly reservationsQueue: ReservationsQueue,
|
||||
|
||||
@Inject(ReservationsService)
|
||||
private readonly reservationsService: ReservationsService,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue