Skip to content

Commit

Permalink
Merge pull request RocketChat#954 from Shailesh351/sb_fix_scheduler_api
Browse files Browse the repository at this point in the history
[FIX] cancelJobByDataQuery for passing proper data query
  • Loading branch information
ear-dev committed Oct 6, 2021
2 parents 00a10cc + afb878d commit f14ef27
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions app/apps/server/bridges/scheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,12 @@ export class AppSchedulerBridge extends SchedulerBridge {
* @returns Promise<void>
*/
protected async cancelJobByDataQuery(data: object, appId: string): Promise<void> {
this.orch.debugLog(`Canceling all jobs of App ${ appId } matching ${ JSON.stringify(data) }`);
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 }, data });
await this.scheduler.cancel({ name: { $regex: matcher }, ...dataQuery });
} catch (e) {
console.error(e);
}
Expand All @@ -209,6 +210,23 @@ export class AppSchedulerBridge extends SchedulerBridge {
}
}

private getQueryFromObject(parent: string, data: object): object {
const query: {
[key: string]: any;
} = {};
for (const [key, value] of Object.entries(data)) {
if (typeof value === 'object') {
const q = this.getQueryFromObject(key, value);
for (const [key, value] of Object.entries(q)) {
query[`${ parent }.${ key }`] = value;
}
} else {
query[`${ parent }.${ key }`] = value;
}
}
return query;
}

private decorateJobData(jobData: object | undefined, appId: string): object {
return Object.assign({}, jobData, { appId });
}
Expand Down

0 comments on commit f14ef27

Please sign in to comment.