Creating job to record monitor during reservation
This commit is contained in:
parent
2d106deb77
commit
203dea910b
3 changed files with 28 additions and 6 deletions
|
|
@ -6,6 +6,11 @@ import { MONITORING_QUEUE_NAME } from './config'
|
|||
import { MonitorType } from './entity'
|
||||
import { MonitorsService } from './service'
|
||||
|
||||
export interface MonitoringQueueData {
|
||||
type: MonitorType
|
||||
data: unknown
|
||||
}
|
||||
|
||||
@Processor(MONITORING_QUEUE_NAME)
|
||||
export class MonitoringWorker {
|
||||
constructor(
|
||||
|
|
@ -14,9 +19,7 @@ export class MonitoringWorker {
|
|||
) {}
|
||||
|
||||
@Process()
|
||||
async handleMonitoringCourtsJob(
|
||||
job: Job<{ type: MonitorType; data: unknown }>,
|
||||
) {
|
||||
async handleMonitoringCourtsJob(job: Job<MonitoringQueueData>) {
|
||||
await this.monitorsService.performMonitor(job.data.type, job.data.data)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
import { InjectQueue } from '@nestjs/bull'
|
||||
import { Inject, Injectable } from '@nestjs/common'
|
||||
import { ConfigService } from '@nestjs/config'
|
||||
import { Queue } from 'bull'
|
||||
import { instanceToPlain } from 'class-transformer'
|
||||
import { Dayjs } from 'dayjs'
|
||||
import path from 'path'
|
||||
|
|
@ -7,6 +9,9 @@ import { ElementHandle, Page } from 'puppeteer'
|
|||
|
||||
import dayjs from '../../common/dayjs'
|
||||
import { LoggerService } from '../../logger/service.logger'
|
||||
import { MONITORING_QUEUE_NAME } from '../../monitoring/config'
|
||||
import { MonitorType } from '../../monitoring/entity'
|
||||
import { MonitoringQueueData } from '../../monitoring/worker'
|
||||
import { Reservation } from '../../reservations/entity'
|
||||
import { EmptyPage } from '../pages/empty'
|
||||
|
||||
|
|
@ -90,6 +95,9 @@ export class BaanReserverenService {
|
|||
private password: string
|
||||
|
||||
constructor(
|
||||
@InjectQueue(MONITORING_QUEUE_NAME)
|
||||
private readonly monitoringQueue: Queue<MonitoringQueueData>,
|
||||
|
||||
@Inject(LoggerService)
|
||||
private readonly loggerService: LoggerService,
|
||||
|
||||
|
|
@ -598,7 +606,11 @@ export class BaanReserverenService {
|
|||
await this.init()
|
||||
await this.navigateToDay(date)
|
||||
}
|
||||
return await this.getAllCourtStatuses()
|
||||
const statuses = await this.getAllCourtStatuses()
|
||||
await this.monitoringQueue.add({
|
||||
type: MonitorType.CourtReservations,
|
||||
data: statuses,
|
||||
})
|
||||
} catch (error: unknown) {
|
||||
this.loggerService.error('Failed to monitor court reservations')
|
||||
if (!swallowError) {
|
||||
|
|
|
|||
|
|
@ -2,15 +2,22 @@ import { BullModule } from '@nestjs/bull'
|
|||
import { Module } from '@nestjs/common'
|
||||
|
||||
import { LoggerModule } from '../logger/module'
|
||||
import { MONITORING_QUEUE_NAME } from '../monitoring/config'
|
||||
import { MonitoringModule } from '../monitoring/module'
|
||||
import { BaanReserverenService } from './baanreserveren/service'
|
||||
import { EmptyPageFactory } from './pages/empty'
|
||||
import { RunnerService } from './service'
|
||||
|
||||
@Module({
|
||||
providers: [RunnerService, BaanReserverenService, EmptyPageFactory],
|
||||
providers: [
|
||||
RunnerService,
|
||||
BaanReserverenService,
|
||||
MonitoringModule,
|
||||
EmptyPageFactory,
|
||||
],
|
||||
imports: [
|
||||
LoggerModule,
|
||||
BullModule.registerQueueAsync({ name: 'reservations' }),
|
||||
BullModule.registerQueueAsync({ name: MONITORING_QUEUE_NAME }),
|
||||
],
|
||||
exports: [EmptyPageFactory, BaanReserverenService],
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue