mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2026-03-10 18:41:46 +00:00
45 lines
1.1 KiB
TypeScript
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,
|
|
},
|
|
);
|
|
}
|
|
}
|