Adding monitoring queue
This commit is contained in:
parent
dd50bbec78
commit
9bed0e21f1
4 changed files with 32 additions and 2 deletions
1
src/monitoring/config.ts
Normal file
1
src/monitoring/config.ts
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
export const MONITORING_QUEUE_NAME = 'monitoring'
|
||||||
|
|
@ -1,13 +1,20 @@
|
||||||
|
import { BullModule } from '@nestjs/bull'
|
||||||
import { Module } from '@nestjs/common'
|
import { Module } from '@nestjs/common'
|
||||||
import { TypeOrmModule } from '@nestjs/typeorm'
|
import { TypeOrmModule } from '@nestjs/typeorm'
|
||||||
|
|
||||||
import { LoggerModule } from '../logger/module'
|
import { LoggerModule } from '../logger/module'
|
||||||
import { NtfyModule } from '../ntfy/module'
|
import { NtfyModule } from '../ntfy/module'
|
||||||
|
import { MONITORING_QUEUE_NAME } from './config'
|
||||||
import { Monitor } from './entity'
|
import { Monitor } from './entity'
|
||||||
import { MonitorsService } from './service'
|
import { MonitorsService } from './service'
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [LoggerModule, NtfyModule, TypeOrmModule.forFeature([Monitor])],
|
imports: [
|
||||||
|
LoggerModule,
|
||||||
|
NtfyModule,
|
||||||
|
TypeOrmModule.forFeature([Monitor]),
|
||||||
|
BullModule.registerQueueAsync({ name: MONITORING_QUEUE_NAME }),
|
||||||
|
],
|
||||||
providers: [MonitorsService],
|
providers: [MonitorsService],
|
||||||
exports: [MonitorsService],
|
exports: [MonitorsService],
|
||||||
})
|
})
|
||||||
|
|
|
||||||
22
src/monitoring/worker.ts
Normal file
22
src/monitoring/worker.ts
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
import { Process, Processor } from '@nestjs/bull'
|
||||||
|
import { Inject } from '@nestjs/common'
|
||||||
|
import { Job } from 'bull'
|
||||||
|
|
||||||
|
import { MONITORING_QUEUE_NAME } from './config'
|
||||||
|
import { MonitorType } from './entity'
|
||||||
|
import { MonitorsService } from './service'
|
||||||
|
|
||||||
|
@Processor(MONITORING_QUEUE_NAME)
|
||||||
|
export class MonitoringWorker {
|
||||||
|
constructor(
|
||||||
|
@Inject(MonitorsService)
|
||||||
|
private readonly monitorsService: MonitorsService,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
@Process()
|
||||||
|
async handleMonitoringCourtsJob(
|
||||||
|
job: Job<{ type: MonitorType; data: unknown }>,
|
||||||
|
) {
|
||||||
|
await this.monitorsService.performMonitor(job.data.type, job.data.data)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -10,9 +10,9 @@ import {
|
||||||
NoCourtAvailableError,
|
NoCourtAvailableError,
|
||||||
} from '../runner/baanreserveren/service'
|
} from '../runner/baanreserveren/service'
|
||||||
import { RESERVATIONS_QUEUE_NAME } from './config'
|
import { RESERVATIONS_QUEUE_NAME } from './config'
|
||||||
|
import { DAILY_RESERVATIONS_ATTEMPTS } from './cron'
|
||||||
import { Reservation } from './entity'
|
import { Reservation } from './entity'
|
||||||
import { ReservationsService } from './service'
|
import { ReservationsService } from './service'
|
||||||
import { DAILY_RESERVATIONS_ATTEMPTS } from './cron'
|
|
||||||
|
|
||||||
@Processor(RESERVATIONS_QUEUE_NAME)
|
@Processor(RESERVATIONS_QUEUE_NAME)
|
||||||
export class ReservationsWorker {
|
export class ReservationsWorker {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue