From a41b15331a85a3d16f57db4bffe95a30bc571aca Mon Sep 17 00:00:00 2001 From: I-Have-An-Issue <34550332+I-Have-An-Issue@users.noreply.github.com> Date: Fri, 17 Feb 2023 21:13:08 -0500 Subject: [PATCH] Rotate job ids on job --- src/lib/classes/RenderJob.js | 7 ++++++ src/routes/render/user.js | 44 ++++++++++++++++++------------------ 2 files changed, 29 insertions(+), 22 deletions(-) diff --git a/src/lib/classes/RenderJob.js b/src/lib/classes/RenderJob.js index 227f2eb..8b64c3f 100644 --- a/src/lib/classes/RenderJob.js +++ b/src/lib/classes/RenderJob.js @@ -3,6 +3,7 @@ const chalk = require('chalk') const Job = require("./Job.js") const logger = require("../logger.js") +const { randomUUID } = require("crypto") class RenderJob extends Job { constructor() { @@ -10,6 +11,8 @@ class RenderJob extends Job { } async RenderHeadshot(id) { + this.id = randomUUID() + const running = this.started if (!running) { const started = await this.Start() @@ -46,6 +49,8 @@ class RenderJob extends Job { } async RenderBodyshot(id, three_d = false) { + this.id = randomUUID() + const running = this.started if (!running) { const started = await this.Start() @@ -84,6 +89,8 @@ class RenderJob extends Job { } async RenderAsset(id, three_d = false) { + this.id = randomUUID() + const running = this.started if (!running) { const started = await this.Start() diff --git a/src/routes/render/user.js b/src/routes/render/user.js index 0933628..76f7376 100644 --- a/src/routes/render/user.js +++ b/src/routes/render/user.js @@ -1,39 +1,39 @@ -const express = require("express"); -const app = express.Router(); +const express = require("express") +const app = express.Router() -const RenderJob = require("../../lib/classes/RenderJob.js"); +const RenderJob = require("../../lib/classes/RenderJob.js") app.get("/:id", async (request, response) => { - const { params, query } = request; - const job = new RenderJob(); - let body = {}; + const { params, query } = request + const job = new RenderJob() + let body = {} - const headshot = await job.RenderHeadshot(params.id).catch((_) => _); + const headshot = await job.RenderHeadshot(params.id).catch((_) => _) if (headshot?.message) { - job.Stop(); - return response.status(500).json({ error: headshot.message }); + job.Stop() + return response.status(500).json({ error: headshot.message }) } - body.headshot = headshot; + body.headshot = headshot - const bodyshot = await job.RenderBodyshot(params.id).catch((_) => _); + const bodyshot = await job.RenderBodyshot(params.id).catch((_) => _) if (bodyshot?.message) { - job.Stop(); - return response.status(500).json({ error: bodyshot.message }); + job.Stop() + return response.status(500).json({ error: bodyshot.message }) } - body.bodyshot = bodyshot; + body.bodyshot = bodyshot if (query.three_d) { - const three_d = await job.RenderBodyshot(params.id, true).catch((_) => _); + const three_d = await job.RenderBodyshot(params.id, true).catch((_) => _) if (three_d?.message) { - job.Stop(); - return response.status(500).json({ error: three_d.message }); + job.Stop() + return response.status(500).json({ error: three_d.message }) } - body.three_d = three_d; + body.three_d = three_d } - job.Stop(); + job.Stop() - return response.json(body); -}); + return response.json(body) +}) -module.exports = app; +module.exports = app