update: the quota sync service
This commit is contained in:
@@ -90,10 +90,10 @@ export class QuotaSyncProcessor extends WorkerProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async handleSyncComprehensiveQuota(_job: Job<ISyncComprehensiveQuotaJob>): Promise<void> {
|
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();
|
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 {
|
private logJobSuccess(job: Job, startTime: number): void {
|
||||||
|
|||||||
@@ -34,10 +34,11 @@ export class QuotaSyncService {
|
|||||||
async setupCronJob(): Promise<void> {
|
async setupCronJob(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
// Remove any existing cron jobs for this job type
|
// 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
|
// Add new repeatable job
|
||||||
await this.quotaSyncQueue.add(
|
const job = await this.quotaSyncQueue.add(
|
||||||
QUOTA_SYNC_QUEUE.SYNC_COMPREHENSIVE_QUOTA_JOB,
|
QUOTA_SYNC_QUEUE.SYNC_COMPREHENSIVE_QUOTA_JOB,
|
||||||
{},
|
{},
|
||||||
{
|
{
|
||||||
@@ -49,11 +50,11 @@ export class QuotaSyncService {
|
|||||||
delay: 2000,
|
delay: 2000,
|
||||||
},
|
},
|
||||||
repeat: {
|
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");
|
this.logger.log("Quota sync cron job scheduled to run every hour");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.logger.error("Failed to setup quota sync cron job", error);
|
this.logger.error("Failed to setup quota sync cron job", error);
|
||||||
@@ -66,8 +67,19 @@ export class QuotaSyncService {
|
|||||||
*/
|
*/
|
||||||
async removeCronJob(): Promise<void> {
|
async removeCronJob(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
await this.quotaSyncQueue.removeJobScheduler(QUOTA_SYNC_QUEUE.SYNC_COMPREHENSIVE_QUOTA_JOB);
|
// Remove any existing cron jobs for this job type
|
||||||
this.logger.log("Quota sync cron job removed");
|
// 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) {
|
} catch (error) {
|
||||||
this.logger.error("Failed to remove quota sync cron job", error);
|
this.logger.error("Failed to remove quota sync cron job", error);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user