🔧 Refactored the getJobResultStatistics method

This commit is contained in:
2023-08-24 23:45:51 -04:00
parent fd4dd1d5c4
commit bde548695c

View File

@@ -27,7 +27,7 @@ export default class JobQueueService extends Service {
handler: async (ctx: Context<{}>) => { handler: async (ctx: Context<{}>) => {
console.log(ctx.params); console.log(ctx.params);
return await this.$resolve("jobqueue").getJobCounts(); return await this.$resolve("jobqueue").getJobCounts();
} },
}, },
toggle: { toggle: {
rest: "GET /toggle", rest: "GET /toggle",
@@ -170,19 +170,19 @@ export default class JobQueueService extends Service {
getJobResultStatistics: { getJobResultStatistics: {
rest: "GET /getJobResultStatistics", rest: "GET /getJobResultStatistics",
handler: async (ctx: Context<{}>) => { handler: async (ctx: Context<{}>) => {
const result = await JobResult.aggregate([ return await JobResult.aggregate([
{ {
$group: { $group: {
_id: "$_id", _id: "$status",
jobResults: { $addToSet: "status" } // data: { $push: "$$ROOT._id" },
count: { $sum: 1 },
}, },
}, },
{ $sort: { timestamp: -1 } }, { $sort: { timestamp: -1 } },
{ $skip: 0 }, { $skip: 0 },
{ $limit: 5 }, ]);
]) },
}
}, },
}, },
@@ -191,14 +191,16 @@ export default class JobQueueService extends Service {
async "enqueue.async.active"(ctx: Context<{ id: Number }>) { async "enqueue.async.active"(ctx: Context<{ id: Number }>) {
console.log(`Job ID ${ctx.params.id} is set to active.`); console.log(`Job ID ${ctx.params.id} is set to active.`);
}, },
async "drained"(ctx) { async drained(ctx) {
console.log("Queue drained."); console.log("Queue drained.");
await this.broker.call("socket.broadcast", { await this.broker.call("socket.broadcast", {
namespace: "/", namespace: "/",
event: "action", event: "action",
args: [{ args: [
type: "LS_IMPORT_QUEUE_DRAINED", {
}], type: "LS_IMPORT_QUEUE_DRAINED",
},
],
}); });
}, },
async "enqueue.async.completed"(ctx: Context<{ id: Number }>) { async "enqueue.async.completed"(ctx: Context<{ id: Number }>) {
@@ -228,7 +230,6 @@ export default class JobQueueService extends Service {
failedReason: {}, failedReason: {},
}); });
console.log(`Job ID ${ctx.params.id} completed.`); console.log(`Job ID ${ctx.params.id} completed.`);
}, },
@@ -256,7 +257,6 @@ export default class JobQueueService extends Service {
}, },
], ],
}); });
}, },
}, },
}); });