39 lines
1.1 KiB
TypeScript
39 lines
1.1 KiB
TypeScript
import { Controller, Post, HttpCode, UseGuards, Get, Query } from '@nestjs/common';
|
|
import { SchedulerRegistry } from '@nestjs/schedule';
|
|
import { InjectRepository } from '@nestjs/typeorm';
|
|
import { Repository } from 'typeorm';
|
|
import { AdminAuthGuard } from '../auth/admin.guard';
|
|
import { IngestRunEntity } from '../entities/ingest-run.entity';
|
|
|
|
@Controller('admin/ingest')
|
|
@UseGuards(AdminAuthGuard)
|
|
export class AdminIngestController {
|
|
constructor(
|
|
private readonly schedulerRegistry: SchedulerRegistry,
|
|
@InjectRepository(IngestRunEntity)
|
|
private readonly runs: Repository<IngestRunEntity>,
|
|
) {}
|
|
|
|
@Post('pause')
|
|
@HttpCode(200)
|
|
pause() {
|
|
const job = this.schedulerRegistry.getCronJob('ingest_job');
|
|
job.stop();
|
|
return { ok: true, paused: true };
|
|
}
|
|
|
|
@Post('resume')
|
|
@HttpCode(200)
|
|
resume() {
|
|
const job = this.schedulerRegistry.getCronJob('ingest_job');
|
|
job.start();
|
|
return { ok: true, resumed: true };
|
|
}
|
|
|
|
@Get('runs')
|
|
async listRuns(@Query('limit') limit?: string) {
|
|
const take = limit ? Math.min(Number(limit) || 20, 200) : 20;
|
|
return this.runs.find({ order: { startedAt: 'DESC' }, take });
|
|
}
|
|
}
|