Files
bidding_watcher/src/crawler/crawler.controller.ts

39 lines
1.2 KiB
TypeScript
Raw Normal View History

import { Controller, Post, Get } from '@nestjs/common';
2026-01-09 23:18:52 +08:00
import { BidCrawlerService } from './services/bid-crawler.service';
@Controller('api/crawler')
export class CrawlerController {
private isCrawling = false;
2026-01-09 23:18:52 +08:00
constructor(private readonly crawlerService: BidCrawlerService) {}
@Get('status')
getStatus() {
return { isCrawling: this.isCrawling };
}
2026-01-09 23:18:52 +08:00
@Post('run')
async runCrawl() {
if (this.isCrawling) {
return { message: 'Crawl is already running' };
}
this.isCrawling = true;
2026-01-09 23:18:52 +08:00
// We don't await this because we want it to run in the background
// and return immediately, or we can await if we want to user to wait.
2026-01-09 23:18:52 +08:00
// Given the requirement "Immediate Crawl", usually implies triggering it.
// However, for a better UI experience, we might want to wait or just trigger.
// Let's await it so that user knows when it's done (or failed),
2026-01-09 23:18:52 +08:00
// assuming it doesn't take too long for the mock.
// Real crawling might take long, so background is better.
// For this prototype, I'll await it to show completion.
try {
await this.crawlerService.crawlAll();
return { message: 'Crawl completed successfully' };
} finally {
this.isCrawling = false;
}
2026-01-09 23:18:52 +08:00
}
}