🔧 Refactored the getJobResultStatistics method
This commit is contained in:
@@ -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 }>) {
|
||||||
@@ -227,7 +229,6 @@ export default class JobQueueService extends Service {
|
|||||||
timestamp: job.timestamp,
|
timestamp: job.timestamp,
|
||||||
failedReason: {},
|
failedReason: {},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
console.log(`Job ID ${ctx.params.id} completed.`);
|
console.log(`Job ID ${ctx.params.id} completed.`);
|
||||||
},
|
},
|
||||||
@@ -254,9 +255,8 @@ export default class JobQueueService extends Service {
|
|||||||
failedJobCount,
|
failedJobCount,
|
||||||
importResult: job,
|
importResult: job,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user