Added dev reporting

This commit is contained in:
Dunemask 2022-07-07 21:45:38 +00:00
parent d4acc497f1
commit f559b653f2
10 changed files with 145 additions and 12 deletions

View file

@ -1,5 +1,6 @@
import { v4 } from "uuid";
import applyJob from "./kubernetes.js";
import buildJob from "./job-builder.js";
const maxJobs = process.env.MAX_JOBS ? parseInt(process.env.MAX_JOBS) : 3;
@ -41,7 +42,8 @@ class JobManager {
this.clientMaxJobs
)
throw Error("Client's Active Jobs Exceeded!");
const job = { ...jobRequest };
const job = buildJob(jobRequest, id);
job.id = v4();
job.log = [];
this.clients[id].jobs.push(job);

59
lib/core/job-builder.js Normal file
View file

@ -0,0 +1,59 @@
const baseCommand = "node";
const suiteEntry = "dev/suite/runner.js";
const pipelineMapping = [
{
id: 0,
pipeline: [{ name: "primary" }, { name: "secondary", delay: 5000 }],
},
];
const buildCommon = (jobRequest) => {
const { testName } = jobRequest;
if (!testName) throw Error("'testName' must be provided!");
const command = [baseCommand, suiteEntry, `test=${testName}`];
// Apply Common Flags
command.push("isRetry=false");
// Return new request
return { ...jobRequest, command };
};
const buildSingle = (jobReq) => jobReq;
const buildMarker = (jobReq) => {};
const buildProject = (jobReq) => {};
const pipelineMaxLife = (testName) => {
const pipelines = pipelineMapping
.filter((m) => m.pipeline.find((t) => t.name === testName))
.map((m) => m.pipeline);
return Math.max(pipelines.map((p) => p.length)) + 1;
};
const buildCompound = (jobReq, socketId) => {
const { testName, command } = jobReq;
const pipelineLife = jobReq.pipelineLife ?? pipelineMaxLife(testName);
command.push(`pipelineLife=${pipelineLife}`);
command.push(`pipelineDashboardSocket=${socketId}`);
return { ...jobReq, command };
};
const nextCompound = (previousTest) => {};
export default function jobBuilder(jobRequest, id) {
const jobReq = buildCommon(jobRequest, id);
switch (jobRequest.type) {
case "single":
return buildSingle(jobReq);
case "marker":
return buildMarker(jobReq);
case "project":
return buildProject(jobReq);
case "compound":
return buildCompound(jobReq, id);
default:
throw Error("No Job Request Type Specified!");
}
}

View file

@ -9,11 +9,12 @@ import catalog from "../routes/catalog-route.js";
import jobs from "../routes/jobs-route.js";
import mock from "../routes/mock-route.js";
import dev from "../routes/dev-route.js";
const app = express();
// Special Routes
app.all("/", (req, res) => res.redirect("/qualiteer"));
if (process.env.MOCK_ROUTES === "true") app.use(mock);
if(process.env.USE_DEV_ROUTER === "true") app.use("/api/dev",dev);
// Middlewares

14
lib/routes/dev-route.js Normal file
View file

@ -0,0 +1,14 @@
import { Router, json as jsonMiddleware } from "express";
import TestResultsWorker from "../rabbit/workers/TestResultsWorker.js";
const testResultsHandler = new TestResultsWorker();
const router = Router();
router.use(jsonMiddleware());
router.post("/rabbit/TestResults", (req, res) => {
const { testResult } = req.body;
testResultsHandler.onMessage(testResult);
res.sendStatus(200);
});
export default router;