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 { MonitorType } from './entity'
|
||||||
import { MonitorsService } from './service'
|
import { MonitorsService } from './service'
|
||||||
|
|
||||||
|
export interface MonitoringQueueData {
|
||||||
|
type: MonitorType
|
||||||
|
data: unknown
|
||||||
|
}
|
||||||
|
|
||||||
@Processor(MONITORING_QUEUE_NAME)
|
@Processor(MONITORING_QUEUE_NAME)
|
||||||
export class MonitoringWorker {
|
export class MonitoringWorker {
|
||||||
constructor(
|
constructor(
|
||||||
|
|
@ -14,9 +19,7 @@ export class MonitoringWorker {
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
@Process()
|
@Process()
|
||||||
async handleMonitoringCourtsJob(
|
async handleMonitoringCourtsJob(job: Job<MonitoringQueueData>) {
|
||||||
job: Job<{ type: MonitorType; data: unknown }>,
|
|
||||||
) {
|
|
||||||
await this.monitorsService.performMonitor(job.data.type, job.data.data)
|
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 { Inject, Injectable } from '@nestjs/common'
|
||||||
import { ConfigService } from '@nestjs/config'
|
import { ConfigService } from '@nestjs/config'
|
||||||
|
import { Queue } from 'bull'
|
||||||
import { instanceToPlain } from 'class-transformer'
|
import { instanceToPlain } from 'class-transformer'
|
||||||
import { Dayjs } from 'dayjs'
|
import { Dayjs } from 'dayjs'
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
|
|
@ -7,6 +9,9 @@ import { ElementHandle, Page } from 'puppeteer'
|
||||||
|
|
||||||
import dayjs from '../../common/dayjs'
|
import dayjs from '../../common/dayjs'
|
||||||
import { LoggerService } from '../../logger/service.logger'
|
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 { Reservation } from '../../reservations/entity'
|
||||||
import { EmptyPage } from '../pages/empty'
|
import { EmptyPage } from '../pages/empty'
|
||||||
|
|
||||||
|
|
@ -90,6 +95,9 @@ export class BaanReserverenService {
|
||||||
private password: string
|
private password: string
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
|
@InjectQueue(MONITORING_QUEUE_NAME)
|
||||||
|
private readonly monitoringQueue: Queue<MonitoringQueueData>,
|
||||||
|
|
||||||
@Inject(LoggerService)
|
@Inject(LoggerService)
|
||||||
private readonly loggerService: LoggerService,
|
private readonly loggerService: LoggerService,
|
||||||
|
|
||||||
|
|
@ -598,7 +606,11 @@ export class BaanReserverenService {
|
||||||
await this.init()
|
await this.init()
|
||||||
await this.navigateToDay(date)
|
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) {
|
} catch (error: unknown) {
|
||||||
this.loggerService.error('Failed to monitor court reservations')
|
this.loggerService.error('Failed to monitor court reservations')
|
||||||
if (!swallowError) {
|
if (!swallowError) {
|
||||||
|
|
|
||||||
|
|
@ -2,15 +2,22 @@ import { BullModule } from '@nestjs/bull'
|
||||||
import { Module } from '@nestjs/common'
|
import { Module } from '@nestjs/common'
|
||||||
|
|
||||||
import { LoggerModule } from '../logger/module'
|
import { LoggerModule } from '../logger/module'
|
||||||
|
import { MONITORING_QUEUE_NAME } from '../monitoring/config'
|
||||||
|
import { MonitoringModule } from '../monitoring/module'
|
||||||
import { BaanReserverenService } from './baanreserveren/service'
|
import { BaanReserverenService } from './baanreserveren/service'
|
||||||
import { EmptyPageFactory } from './pages/empty'
|
import { EmptyPageFactory } from './pages/empty'
|
||||||
import { RunnerService } from './service'
|
import { RunnerService } from './service'
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
providers: [RunnerService, BaanReserverenService, EmptyPageFactory],
|
providers: [
|
||||||
|
RunnerService,
|
||||||
|
BaanReserverenService,
|
||||||
|
MonitoringModule,
|
||||||
|
EmptyPageFactory,
|
||||||
|
],
|
||||||
imports: [
|
imports: [
|
||||||
LoggerModule,
|
LoggerModule,
|
||||||
BullModule.registerQueueAsync({ name: 'reservations' }),
|
BullModule.registerQueueAsync({ name: MONITORING_QUEUE_NAME }),
|
||||||
],
|
],
|
||||||
exports: [EmptyPageFactory, BaanReserverenService],
|
exports: [EmptyPageFactory, BaanReserverenService],
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue