update: the quota sync service

This commit is contained in:
mahyargdz
2025-07-15 16:25:25 +03:30
parent 76b29599da
commit 63ddd394c9
2 changed files with 20 additions and 8 deletions
@@ -90,10 +90,10 @@ export class QuotaSyncProcessor extends WorkerProcessor {
}
private async handleSyncComprehensiveQuota(_job: Job<ISyncComprehensiveQuotaJob>): Promise<void> {
this.logger.log("Processing comprehensive quota sync");
this.logger.debug("Processing comprehensive quota sync .........................");
await this.quotaSyncService.syncAllQuotas();
this.logger.log("Successfully completed comprehensive quota sync");
this.logger.debug("Successfully completed comprehensive quota sync .........................");
}
private logJobSuccess(job: Job, startTime: number): void {
@@ -34,10 +34,11 @@ export class QuotaSyncService {
async setupCronJob(): Promise<void> {
try {
// Remove any existing cron jobs for this job type
await this.quotaSyncQueue.removeJobScheduler(QUOTA_SYNC_QUEUE.SYNC_COMPREHENSIVE_QUOTA_JOB);
// Get all repeatable jobs and remove the one with matching name
await this.removeCronJob();
// Add new repeatable job
await this.quotaSyncQueue.add(
const job = await this.quotaSyncQueue.add(
QUOTA_SYNC_QUEUE.SYNC_COMPREHENSIVE_QUOTA_JOB,
{},
{
@@ -49,11 +50,11 @@ export class QuotaSyncService {
delay: 2000,
},
repeat: {
pattern: "0 * * * *", // Every hour at minute 0 (cron pattern)
pattern: "0/1 * * * *", // Every hour at minute 0 (cron pattern)
},
},
);
this.logger.debug(`Added new cron job with ID: ${job.id}`);
this.logger.log("Quota sync cron job scheduled to run every hour");
} catch (error) {
this.logger.error("Failed to setup quota sync cron job", error);
@@ -66,8 +67,19 @@ export class QuotaSyncService {
*/
async removeCronJob(): Promise<void> {
try {
await this.quotaSyncQueue.removeJobScheduler(QUOTA_SYNC_QUEUE.SYNC_COMPREHENSIVE_QUOTA_JOB);
this.logger.log("Quota sync cron job removed");
// Remove any existing cron jobs for this job type
// Get all repeatable jobs and remove the one with matching name
const repeatableJobs = await this.quotaSyncQueue.getJobSchedulers();
const existingJob = repeatableJobs.filter((job) => job.name === QUOTA_SYNC_QUEUE.SYNC_COMPREHENSIVE_QUOTA_JOB);
if (existingJob.length > 0) {
for (const job of existingJob) {
const removed = await this.quotaSyncQueue.removeJobScheduler(job.key);
this.logger.debug(`Removed existing cron job with key ${job.key}: ${removed}`);
}
} else {
this.logger.debug("No existing cron job found to remove");
}
} catch (error) {
this.logger.error("Failed to remove quota sync cron job", error);
}