Rotate job ids on job

This commit is contained in:
I-Have-An-Issue 2023-02-17 21:13:08 -05:00
parent fe4c081591
commit a41b15331a
No known key found for this signature in database
GPG Key ID: E55435DEA0825091
2 changed files with 29 additions and 22 deletions

View File

@ -3,6 +3,7 @@ const chalk = require('chalk')
const Job = require("./Job.js") const Job = require("./Job.js")
const logger = require("../logger.js") const logger = require("../logger.js")
const { randomUUID } = require("crypto")
class RenderJob extends Job { class RenderJob extends Job {
constructor() { constructor() {
@ -10,6 +11,8 @@ class RenderJob extends Job {
} }
async RenderHeadshot(id) { async RenderHeadshot(id) {
this.id = randomUUID()
const running = this.started const running = this.started
if (!running) { if (!running) {
const started = await this.Start() const started = await this.Start()
@ -46,6 +49,8 @@ class RenderJob extends Job {
} }
async RenderBodyshot(id, three_d = false) { async RenderBodyshot(id, three_d = false) {
this.id = randomUUID()
const running = this.started const running = this.started
if (!running) { if (!running) {
const started = await this.Start() const started = await this.Start()
@ -84,6 +89,8 @@ class RenderJob extends Job {
} }
async RenderAsset(id, three_d = false) { async RenderAsset(id, three_d = false) {
this.id = randomUUID()
const running = this.started const running = this.started
if (!running) { if (!running) {
const started = await this.Start() const started = await this.Start()

View File

@ -1,39 +1,39 @@
const express = require("express"); const express = require("express")
const app = express.Router(); const app = express.Router()
const RenderJob = require("../../lib/classes/RenderJob.js"); const RenderJob = require("../../lib/classes/RenderJob.js")
app.get("/:id", async (request, response) => { app.get("/:id", async (request, response) => {
const { params, query } = request; const { params, query } = request
const job = new RenderJob(); const job = new RenderJob()
let body = {}; let body = {}
const headshot = await job.RenderHeadshot(params.id).catch((_) => _); const headshot = await job.RenderHeadshot(params.id).catch((_) => _)
if (headshot?.message) { if (headshot?.message) {
job.Stop(); job.Stop()
return response.status(500).json({ error: headshot.message }); 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) { if (bodyshot?.message) {
job.Stop(); job.Stop()
return response.status(500).json({ error: bodyshot.message }); return response.status(500).json({ error: bodyshot.message })
} }
body.bodyshot = bodyshot; body.bodyshot = bodyshot
if (query.three_d) { 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) { if (three_d?.message) {
job.Stop(); job.Stop()
return response.status(500).json({ error: three_d.message }); 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