From bde548695c3ebbfbd02455094047b8ec7edfe5d8 Mon Sep 17 00:00:00 2001 From: Rishi Ghan Date: Thu, 24 Aug 2023 23:45:51 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20Refactored=20the=20getJobResultS?= =?UTF-8?q?tatistics=20method?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- services/jobqueue.service.ts | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/services/jobqueue.service.ts b/services/jobqueue.service.ts index 3bbdede..ba96a90 100644 --- a/services/jobqueue.service.ts +++ b/services/jobqueue.service.ts @@ -27,7 +27,7 @@ export default class JobQueueService extends Service { handler: async (ctx: Context<{}>) => { console.log(ctx.params); return await this.$resolve("jobqueue").getJobCounts(); - } + }, }, toggle: { rest: "GET /toggle", @@ -170,19 +170,19 @@ export default class JobQueueService extends Service { getJobResultStatistics: { rest: "GET /getJobResultStatistics", handler: async (ctx: Context<{}>) => { - const result = await JobResult.aggregate([ + return await JobResult.aggregate([ { $group: { - _id: "$_id", - jobResults: { $addToSet: "status" } + _id: "$status", + // data: { $push: "$$ROOT._id" }, + count: { $sum: 1 }, }, - }, + { $sort: { timestamp: -1 } }, { $skip: 0 }, - { $limit: 5 }, - ]) - } + ]); + }, }, }, @@ -191,14 +191,16 @@ export default class JobQueueService extends Service { async "enqueue.async.active"(ctx: Context<{ id: Number }>) { console.log(`Job ID ${ctx.params.id} is set to active.`); }, - async "drained"(ctx) { + async drained(ctx) { console.log("Queue drained."); await this.broker.call("socket.broadcast", { namespace: "/", event: "action", - args: [{ - type: "LS_IMPORT_QUEUE_DRAINED", - }], + args: [ + { + type: "LS_IMPORT_QUEUE_DRAINED", + }, + ], }); }, async "enqueue.async.completed"(ctx: Context<{ id: Number }>) { @@ -227,7 +229,6 @@ export default class JobQueueService extends Service { timestamp: job.timestamp, failedReason: {}, }); - console.log(`Job ID ${ctx.params.id} completed.`); }, @@ -254,9 +255,8 @@ export default class JobQueueService extends Service { failedJobCount, importResult: job, }, - ], + ], }); - }, }, });