Files
zod-backend/src/cron/repositories/cron-run.repository.ts
2026-01-28 16:03:41 +03:00

45 lines
1.1 KiB
TypeScript

import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { CronRun } from '../entities';
import { CronRunStatus } from '../enums/cron-run-status.enum';
@Injectable()
export class CronRunRepository {
constructor(@InjectRepository(CronRun) private readonly cronRunRepository: Repository<CronRun>) {}
createRun(jobName: string, startedAt: Date): Promise<CronRun> {
return this.cronRunRepository.save(
this.cronRunRepository.create({
jobName,
startedAt,
status: CronRunStatus.SUCCESS,
}),
);
}
markSuccess(id: string, processedCount: number, finishedAt: Date) {
return this.cronRunRepository.update(
{ id },
{
status: CronRunStatus.SUCCESS,
processedCount,
finishedAt,
errorMessage: null,
},
);
}
markFailure(id: string, processedCount: number, finishedAt: Date, errorMessage: string) {
return this.cronRunRepository.update(
{ id },
{
status: CronRunStatus.FAILED,
processedCount,
finishedAt,
errorMessage,
},
);
}
}