first commit
This commit is contained in:
38
apps/api/src/admin/admin.controller.ts
Normal file
38
apps/api/src/admin/admin.controller.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
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 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user