| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- // apps/box-mgnt-api/src/cache-sync/cache-sync-debug.controller.ts
- import {
- Body,
- Controller,
- DefaultValuePipe,
- Logger,
- ParseIntPipe,
- Post,
- Query,
- } from '@nestjs/common';
- import { CacheSyncService } from './cache-sync.service';
- import { IsOptional, IsString } from 'class-validator';
- class ScheduleAdRefreshDto {
- @IsString()
- adId!: string;
- @IsOptional()
- @IsString()
- adType?: string;
- }
- @Controller('mgnt-debug/cache-sync')
- export class CacheSyncDebugController {
- private readonly logger = new Logger(CacheSyncDebugController.name);
- constructor(private readonly cacheSyncService: CacheSyncService) {}
- /**
- * POST /mgnt-debug/cache-sync/channel/refresh-all
- * Schedules a CHANNEL + REFRESH_ALL action.
- */
- @Post('channel/refresh-all')
- async scheduleChannelRefreshAll() {
- await this.cacheSyncService.scheduleChannelRefreshAll();
- this.logger.log('Scheduled CHANNEL REFRESH_ALL');
- return { ok: true, message: 'Scheduled CHANNEL REFRESH_ALL' };
- }
- /**
- * POST /mgnt-debug/cache-sync/category/refresh-all
- * Schedules a CATEGORY + REFRESH_ALL action.
- */
- @Post('category/refresh-all')
- async scheduleCategoryRefreshAll() {
- await this.cacheSyncService.scheduleCategoryRefreshAll();
- this.logger.log('Scheduled CATEGORY REFRESH_ALL');
- return { ok: true, message: 'Scheduled CATEGORY REFRESH_ALL' };
- }
- /**
- * POST /mgnt-debug/cache-sync/ad/refresh
- * Body: { adId: number; adType?: string }
- * Schedules AD REFRESH (+ optional AD_POOL REBUILD_POOL if adType provided).
- */
- @Post('ad/refresh')
- async scheduleAdRefresh(@Body() dto: ScheduleAdRefreshDto) {
- const { adId, adType } = dto;
- await this.cacheSyncService.scheduleAdRefresh(adId, adType);
- this.logger.log(
- `Scheduled AD REFRESH for adId=${adId}, adType=${adType ?? 'N/A'}`,
- );
- return {
- ok: true,
- message: 'Scheduled AD REFRESH (and pool rebuild if adType provided)',
- adId,
- adType: adType ?? null,
- };
- }
- /**
- * POST /mgnt-debug/cache-sync/process-once?limit=20
- * Manually processes pending actions (single batch).
- */
- @Post('process-once')
- async processOnce(
- @Query('limit', new DefaultValuePipe(20), ParseIntPipe) limit: number,
- ) {
- await this.cacheSyncService.processPendingOnce(limit);
- return {
- ok: true,
- message: `Processed up to ${limit} pending actions (see logs).`,
- };
- }
- }
|