From 32593c52a96e2f6b79f95f904dd1aa140aedaff0 Mon Sep 17 00:00:00 2001 From: Aditya Bhardwaj Date: Wed, 12 Apr 2023 02:36:46 +0530 Subject: [PATCH] Modify cancelJobByDataQuery to make it blocking --- .../app/apps/server/bridges/scheduler.ts | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/apps/meteor/app/apps/server/bridges/scheduler.ts b/apps/meteor/app/apps/server/bridges/scheduler.ts index c64ffd1d9f874..358e350f9280e 100644 --- a/apps/meteor/app/apps/server/bridges/scheduler.ts +++ b/apps/meteor/app/apps/server/bridges/scheduler.ts @@ -226,18 +226,22 @@ export class AppSchedulerBridge extends SchedulerBridge { * * @returns Promise */ - protected async cancelJobByDataQuery(data: object, appId: string): Promise { - const dataQuery = this.getQueryFromObject('data', data); - this.orch.debugLog(`Canceling all jobs of App ${appId} matching ${JSON.stringify(dataQuery)}`); - await this.startScheduler(); - const matcher = new RegExp(`_${appId}$`); - try { - await this.scheduler.cancel({ name: { $regex: matcher }, ...dataQuery }); - this.orch.debugLog(`Cancelled all jobs of App ${appId} matching ${JSON.stringify(dataQuery)}`); - } catch (e) { - this.orch.debugLog(`Error in Canceling all jobs of App ${appId} matching ${JSON.stringify(dataQuery)}`); - console.error(e); - } + protected cancelJobByDataQuery(data: object, appId: string): Promise { + return new Promise(async (resolve, reject) => { + const dataQuery = this.getQueryFromObject('data', data); + this.orch.debugLog(`Canceling all jobs of App ${appId} matching ${JSON.stringify(dataQuery)}`); + const matcher = new RegExp(`_${appId}$`); + try { + await this.startScheduler(); + const cancel = await this.scheduler.cancel({ name: { $regex: matcher }, ...dataQuery }); + this.orch.debugLog(`Cancelled all jobs of App ${appId} matching ${JSON.stringify(dataQuery)}`); + resolve(cancel); + } catch (e) { + this.orch.debugLog(`Error in Canceling all jobs of App ${appId} matching ${JSON.stringify(dataQuery)}`); + console.error(e); + reject(e); + } + }); } public async startScheduler(): Promise {