🔧 jobResult aggregate query first draft

This commit is contained in:
2023-08-28 23:56:44 -04:00
parent 76d4e6b10f
commit c718456adc
2 changed files with 22 additions and 7 deletions

View File

@@ -173,14 +173,26 @@ export default class JobQueueService extends Service {
return await JobResult.aggregate([
{
$group: {
_id: "$status",
// data: { $push: "$$ROOT._id" },
_id: {
sessionId: "$sessionId",
status: "$status",
},
earliestTimestamp: { $min: "$timestamp" },
count: { $sum: 1 },
},
},
{ $sort: { timestamp: -1 } },
{ $skip: 0 },
{
$group: {
_id: "$_id.sessionId",
statuses: {
$push: {
status: "$_id.status",
earliestTimestamp: "$earliestTimestamp",
count: "$count",
},
},
},
},
]);
},
},
@@ -243,7 +255,7 @@ export default class JobQueueService extends Service {
id: ctx.params.id,
status: "failed",
failedReason: job.failedReason,
sessionId: job.returnvalue.sessionId,
sessionId: job.data.params.sessionId,
timestamp: job.timestamp,
});

View File

@@ -47,6 +47,7 @@ import {
getMimeType,
} from "../utils/file.utils";
import { convertXMLToJSON } from "./xml.utils";
const { MoleculerError } = require("moleculer").Errors;
const fse = require("fs-extra");
const Unrar = require("unrar");
interface RarFile {
@@ -367,7 +368,9 @@ export const extractFromArchive = async (filePath: string) => {
console.error(
"Error inferring filetype for comicinfo.xml extraction."
);
throw new Error("Cannot infer filetype");
throw new MoleculerError({}, 500, "FILETYPE_INFERENCE_ERROR", {
data: { message: "Cannot infer filetype."},
});
}
};