Replit Commit
This commit is contained in:
commit
f49f965a42
41 changed files with 32720 additions and 0 deletions
8
bin/app.js
Executable file
8
bin/app.js
Executable file
|
@ -0,0 +1,8 @@
|
|||
#!/usr/bin/env node
|
||||
import "dotenv/config"; // Load Envars
|
||||
import Qualiteer from "qualiteer";
|
||||
|
||||
const qltr = new Qualiteer();
|
||||
await qltr.start();
|
||||
|
||||
process.env.INTERNAL_EXECUTOR = "true";
|
5
dev/other.js
Normal file
5
dev/other.js
Normal file
|
@ -0,0 +1,5 @@
|
|||
const cap = 60;
|
||||
|
||||
const logNow = () => console.log(Date.now());
|
||||
|
||||
for (var i = 0; i < cap; i++) setTimeout(logNow, i * 1000);
|
54
dev/views/TestCtx.jsx
Normal file
54
dev/views/TestCtx.jsx
Normal file
|
@ -0,0 +1,54 @@
|
|||
import { useContext } from "react";
|
||||
import { Initiator } from "qualiteer/web-clients";
|
||||
import JobContext from "../ctx/JobContext.jsx";
|
||||
|
||||
const cmd = `node other.js`;
|
||||
export default function Test() {
|
||||
const {
|
||||
state: jobState,
|
||||
dispatch: jobDispatch,
|
||||
jobUpdate,
|
||||
jobCreate
|
||||
} = useContext(JobContext);
|
||||
|
||||
function onLog(d) {
|
||||
const job = jobState.jobs[0];
|
||||
job.log.push(d);
|
||||
jobUpdate(job.id, job);
|
||||
console.log(d);
|
||||
console.log(jobState);
|
||||
}
|
||||
|
||||
async function startJob() {
|
||||
console.log("Wanting to start");
|
||||
const url = "https://Qualiteer.elijahparker3.repl.co";
|
||||
// Create an initiator and make a job request
|
||||
const primary = new Initiator(url);
|
||||
const jobRequest = { command: cmd };
|
||||
|
||||
const job = await primary.newJob(jobRequest, onLog, () =>
|
||||
console.log("Primary Job Concluded")
|
||||
);
|
||||
jobCreate(job);
|
||||
|
||||
console.log("Started");
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="test">
|
||||
<h1>vv Info vv </h1>
|
||||
<button onClick={startJob}>Start</button>
|
||||
{jobState.jobs.map((j) =>
|
||||
j.log.map((l, i) => (
|
||||
<div className="line" key={i}>
|
||||
{l}
|
||||
<br />
|
||||
</div>
|
||||
))
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
|
||||
/*
|
||||
}*/
|
||||
}
|
38
dev/views/TestSimple.jsx
Normal file
38
dev/views/TestSimple.jsx
Normal file
|
@ -0,0 +1,38 @@
|
|||
import { useState } from "react";
|
||||
import { Initiator } from "qualiteer/web-clients";
|
||||
|
||||
const cmd = `node other.js`;
|
||||
export default function Test() {
|
||||
const [job, setJob] = useState({ log: ["INTRO"] });
|
||||
|
||||
function onLog(d) {
|
||||
const j = { ...job };
|
||||
j.log.push(d);
|
||||
setJob(j);
|
||||
}
|
||||
|
||||
async function startJob() {
|
||||
console.log("Wanting to start");
|
||||
const url = "https://Qualiteer.elijahparker3.repl.co";
|
||||
// Create an initiator and make a job request
|
||||
const primary = new Initiator(url);
|
||||
const job = { command: cmd };
|
||||
await primary.newJob(job, onLog, () =>
|
||||
console.log("Primary Job Concluded")
|
||||
);
|
||||
console.log("Started");
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="test">
|
||||
<h1>vv Info vv </h1>
|
||||
<button onClick={startJob}>Start</button>
|
||||
{job.log.map((l, i) => (
|
||||
<div className="line" key={i}>
|
||||
{l}
|
||||
<br />
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
55
lib/core/JobManager.js
Normal file
55
lib/core/JobManager.js
Normal file
|
@ -0,0 +1,55 @@
|
|||
import { v4 } from "uuid";
|
||||
import doExec from "./internal-exec.js";
|
||||
|
||||
export default class JobManager {
|
||||
constructor(clientMaxJobs) {
|
||||
this.clientMaxJobs = clientMaxJobs;
|
||||
this.clients = {};
|
||||
}
|
||||
|
||||
getJob(clientId, jobId) {
|
||||
return this.clients[clientId].jobs.find((j) => j.id === jobId);
|
||||
}
|
||||
|
||||
getJobById(jobId) {
|
||||
for (var client of Object.values(this.clients)) {
|
||||
const job = client.jobs.find((j) => j.id === jobId);
|
||||
if (!job) continue;
|
||||
return job;
|
||||
}
|
||||
}
|
||||
|
||||
pushLog(jobId, log) {
|
||||
const job = this.getJobById(jobId);
|
||||
if (log instanceof Array) job.log.push(...log);
|
||||
else job.log.push(log);
|
||||
}
|
||||
|
||||
closeJob(jobId, exitcode) {
|
||||
const job = this.getJobById(jobId);
|
||||
job.exitcode = exitcode;
|
||||
}
|
||||
|
||||
newJob(jobRequest, id) {
|
||||
if (!jobRequest) throw Error("Request Must Be Object!");
|
||||
if (!this.clients[id]) this.clients[id] = { jobs: [] };
|
||||
const client = this.clients[id];
|
||||
if (
|
||||
client.jobs.filter((j) => j.exitcode === undefined).length >=
|
||||
this.clientMaxJobs
|
||||
)
|
||||
throw Error("Client's Active Jobs Exceeded!");
|
||||
const job = { ...jobRequest };
|
||||
job.id = v4();
|
||||
job.log = [];
|
||||
this.clients[id].jobs.push(job);
|
||||
if (process.env.INTERNAL_EXECUTOR === "true") doExec(job);
|
||||
return { ...job };
|
||||
}
|
||||
|
||||
removeJob(clientId, id) {
|
||||
this.clients[clientId].jobs = this.clients[clientId].jobs.filter(
|
||||
(j) => j.id !== id
|
||||
);
|
||||
}
|
||||
}
|
43
lib/core/Qualiteer.js
Normal file
43
lib/core/Qualiteer.js
Normal file
|
@ -0,0 +1,43 @@
|
|||
import "dotenv/config"; // Load Envars
|
||||
|
||||
// Imports
|
||||
import fig from "figlet";
|
||||
import http from "http";
|
||||
import { INFO, OK, logInfo } from "../util/logging.js";
|
||||
// import "../utils/preload.js"; // Load Globals
|
||||
|
||||
// Import Core Modules
|
||||
import applySockets from "../sockets/handler.js";
|
||||
import JobManager from "./JobManager.js";
|
||||
|
||||
// Constants
|
||||
const title = "QLTR";
|
||||
const port = process.env.QUALITEER_DEV_PORT ?? 52000;
|
||||
|
||||
// Class
|
||||
export default class Qualiteer {
|
||||
constructor(options = {}) {
|
||||
for (var k in options) this[k] = options[k];
|
||||
this.jobs = new JobManager(options.maxClientJobs ?? 3);
|
||||
this.port = options.port ?? port;
|
||||
}
|
||||
|
||||
async _preinitialize() {
|
||||
logInfo(fig.textSync(title, "Cosmike"));
|
||||
INFO("INIT", "Initializing...");
|
||||
this.app = (await import("./server.js")).default;
|
||||
this.server = http.createServer(this.app);
|
||||
this.sockets = applySockets(this.server, this.jobs);
|
||||
}
|
||||
|
||||
start() {
|
||||
const qt = this;
|
||||
return new Promise(async function init(res) {
|
||||
await qt._preinitialize();
|
||||
qt.server.listen(qt.port, function onStart() {
|
||||
OK("SERVER", `Running on ${qt.port}`);
|
||||
res();
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
12
lib/core/internal-exec.js
Normal file
12
lib/core/internal-exec.js
Normal file
|
@ -0,0 +1,12 @@
|
|||
import { INFO } from "../util/logging.js";
|
||||
import Executor from "../sockets/clients/Executor.js";
|
||||
|
||||
export default (job) => {
|
||||
INFO("EXEC", "Starting Internal Executor");
|
||||
try {
|
||||
const exec = new Executor("http://localhost:52000", job);
|
||||
exec.runJob();
|
||||
} catch (err) {
|
||||
ERR("EXEC", err);
|
||||
}
|
||||
};
|
13
lib/core/server.js
Normal file
13
lib/core/server.js
Normal file
|
@ -0,0 +1,13 @@
|
|||
// Imports
|
||||
import express from "express";
|
||||
|
||||
// Routes
|
||||
import results from "../routes/results-route.js";
|
||||
|
||||
const app = express();
|
||||
app.all("/", (req, res) => res.redirect("/qualiteer"));
|
||||
|
||||
// Middlewares
|
||||
|
||||
// Routes
|
||||
app.use("/api/results", results);
|
19
lib/database/migrations/1_create_test_results_table.sql
Normal file
19
lib/database/migrations/1_create_test_results_table.sql
Normal file
|
@ -0,0 +1,19 @@
|
|||
CREATE SEQUENCE test_results_id_seq;
|
||||
CREATE TABLE test_results (
|
||||
id bigint NOT NULL DEFAULT nextval('test_results_seq') PRIMARY KEY,
|
||||
test_name varchar(255) DEFAULT NULL,
|
||||
test_class varchar(255) DEFAULT NULL,
|
||||
test_method varchar(255) DEFAULT NULL,
|
||||
test_path varchar(255) DEFAULT NULL,
|
||||
test_type varchar(32) DEFAULT NULL,
|
||||
test_timestamp timestamptz NOT NULL DEFAULT now(),
|
||||
test_retry BOOLEAN DEFAULT FALSE,
|
||||
origin varchar(255) DEFAULT NULL,
|
||||
failed BOOLEAN DEFAULT FALSE,
|
||||
failed_message varchar(2047) DEFAULT NULL,
|
||||
screenshot_url varchar(255) DEFAULT NULL,
|
||||
weblog_url varchar(255) DEFAULT NULL,
|
||||
);
|
||||
ALTER SEQUENCE test_results_id_seq OWNED BY test_results.id;
|
||||
|
||||
|
120
lib/database/pg-query.js
Normal file
120
lib/database/pg-query.js
Normal file
|
@ -0,0 +1,120 @@
|
|||
const buildPostgresEntry = (entry) => {
|
||||
const pgEntry = { ...entry };
|
||||
Object.keys(pgEntry).forEach((col) => {
|
||||
if (pgEntry[col] === undefined) delete pgEntry[col];
|
||||
});
|
||||
return pgEntry;
|
||||
};
|
||||
|
||||
export const buildPostgresValue = (jsVar) => {
|
||||
if (jsVar === null) return "null";
|
||||
if (typeof jsVar === "string") return buildPostgresString(jsVar);
|
||||
if (Array.isArray(jsVar) && jsVar.length === 0) return "null";
|
||||
if (Array.isArray(jsVar) && isTypeArray(jsVar, "string"))
|
||||
return buildPostgresStringArray(jsVar);
|
||||
return jsVar;
|
||||
};
|
||||
|
||||
const buildPostgresStringArray = (jsonArray) => {
|
||||
if (jsonArray.length === 0) return null;
|
||||
var pgArray = [...jsonArray];
|
||||
var arrayString = "ARRAY [";
|
||||
pgArray.forEach((e, i) => (pgArray[i] = `'${e}'`));
|
||||
arrayString += pgArray.join(",");
|
||||
arrayString += "]";
|
||||
return arrayString;
|
||||
};
|
||||
|
||||
const isTypeArray = (jsonArray, type) =>
|
||||
jsonArray.every((e) => typeof e === type);
|
||||
|
||||
const buildPostgresString = (jsonString) =>
|
||||
(jsonString && `'${jsonString.replaceAll("'", "''")}'`) || null;
|
||||
|
||||
export const insertQuery = (table, jsEntry) => {
|
||||
if (typeof jsEntry !== "object") throw Error("PG Inserts must be objects!");
|
||||
const entry = buildPostgresEntry(jsEntry);
|
||||
const cols = Object.keys(entry);
|
||||
cols.forEach((col, i) => {
|
||||
entry[col] = buildPostgresValue(entry[col]);
|
||||
cols[i] = `"${col}"`;
|
||||
});
|
||||
var query = `INSERT INTO ${table}(${cols.join(",")})\n`;
|
||||
query += `VALUES(${Object.values(entry).join(",")})`;
|
||||
return query;
|
||||
};
|
||||
|
||||
export const deleteQuery = (table, jsEntry) => {
|
||||
if (typeof jsEntry !== "object")
|
||||
throw Error("PG Delete conditionals must be an object!");
|
||||
const entry = buildPostgresEntry(jsEntry);
|
||||
const cols = Object.keys(entry);
|
||||
const conditionals = [];
|
||||
for (var col of cols) {
|
||||
entry[col] = buildPostgresValue(entry[col]);
|
||||
conditionals.push(`x.${col}=${entry[col]}`);
|
||||
}
|
||||
return `DELETE FROM ${table} x WHERE ${conditionals.join(" AND ")}`;
|
||||
};
|
||||
export const onConflictUpdate = (conflicts, updates) => {
|
||||
if (!Array.isArray(conflicts)) throw Error("PG Conflicts must be an array!");
|
||||
if (typeof updates !== "object") throw Error("PG Updates must be objects!");
|
||||
const entry = buildPostgresEntry(updates);
|
||||
var query = `ON CONFLICT (${conflicts.join(",")}) DO UPDATE SET\n`;
|
||||
const cols = Object.keys(entry);
|
||||
for (var col of cols) {
|
||||
entry[col] = buildPostgresValue(entry[col]);
|
||||
}
|
||||
query += cols.map((c) => `${c}=${entry[c]}`).join(",");
|
||||
return query;
|
||||
};
|
||||
export const clearTableQuery = (table) => {
|
||||
return `TRUNCATE ${table}`;
|
||||
};
|
||||
|
||||
export const selectWhereQuery = (table, jsEntry, joinWith) => {
|
||||
if (typeof jsEntry !== "object") throw Error("PG Where must be an object!");
|
||||
const where = buildPostgresEntry(jsEntry);
|
||||
const cols = Object.keys(where);
|
||||
var query = `SELECT * FROM ${table} AS x WHERE\n`;
|
||||
for (var col of cols) {
|
||||
where[col] = buildPostgresValue(where[col]);
|
||||
}
|
||||
return (query += cols.map((c) => `x.${c}=${where[c]}`).join(joinWith));
|
||||
};
|
||||
export const updateWhereQuery = (table, updates, wheres, joinWith) => {
|
||||
if (typeof updates !== "object") throw Error("PG Updates must be an object!");
|
||||
if (typeof wheres !== "object") throw Error("PG Wheres must be an object!");
|
||||
const update = buildPostgresEntry(updates);
|
||||
const where = buildPostgresEntry(wheres);
|
||||
const updateCols = Object.keys(update);
|
||||
const whereCols = Object.keys(where);
|
||||
var query = `UPDATE ${table}\n`;
|
||||
var updateQuery = updateCols
|
||||
.map((c) => `${c} = ${buildPostgresValue(update[c])}`)
|
||||
.join(",");
|
||||
var whereQuery = whereCols
|
||||
.map((c) => `${c} = ${buildPostgresValue(where[c])}`)
|
||||
.join(joinWith);
|
||||
return (query += `SET ${updateQuery} WHERE ${whereQuery}`);
|
||||
};
|
||||
export const updateWhereAnyQuery = (table, updates, wheres) =>
|
||||
updateWhereQuery(table, updates, wheres, " OR ");
|
||||
export const updateWhereAllQuery = (table, updates, wheres) =>
|
||||
updateWhereQuery(table, updates, wheres, " AND ");
|
||||
export const selectWhereAnyQuery = (table, where) =>
|
||||
selectWhereQuery(table, where, " OR ");
|
||||
export const selectWhereAllQuery = (table, where) =>
|
||||
selectWhereQuery(table, where, " AND ");
|
||||
|
||||
export default {
|
||||
selectWhereAnyQuery,
|
||||
selectWhereAllQuery,
|
||||
updateWhereAnyQuery,
|
||||
updateWhereAllQuery,
|
||||
insertQuery,
|
||||
deleteQuery,
|
||||
buildPostgresValue,
|
||||
onConflictUpdate,
|
||||
clearTableQuery,
|
||||
};
|
47
lib/database/postgres.js
Normal file
47
lib/database/postgres.js
Normal file
|
@ -0,0 +1,47 @@
|
|||
// Imports
|
||||
import { migrate } from "postgres-migrations";
|
||||
import createPgp from "pg-promise";
|
||||
import moment from "moment";
|
||||
import { WARN } from "../util/logging.js";
|
||||
// Environment Variables
|
||||
const {
|
||||
POSTGRES_DATABASE: database,
|
||||
POSTGRES_DISABLED: pgDisabled,
|
||||
POSTGRES_HOST: host,
|
||||
POSTGRES_PASSWORD: password,
|
||||
POSTGRES_PORT: port,
|
||||
POSTGRES_USER: user,
|
||||
} = process.env;
|
||||
|
||||
// Postgres-promise Configuration
|
||||
// Ensure dates get saved as UTC date strings
|
||||
// This prevents the parser from doing strange datetime operations
|
||||
const pgp = createPgp();
|
||||
pgp.pg.types.setTypeParser(1114, (str) => moment.utc(str).format());
|
||||
|
||||
// Database Config
|
||||
const dbConfig = {
|
||||
database: database ?? "qualiteer",
|
||||
user: user ?? "postgres",
|
||||
password: password ?? "postgres",
|
||||
host: host ?? "localhost",
|
||||
port: port ?? 5432,
|
||||
ensureDatabaseExists: true,
|
||||
};
|
||||
|
||||
const migrationsDir = "lib/database/migrations";
|
||||
|
||||
const configure = async () => {
|
||||
if (pgDisabled) {
|
||||
WARN("POSTGRES", "Postgres Disabled!");
|
||||
return { query: (str) => INFO("POSTGRES MOCK", str) };
|
||||
}
|
||||
await migrate(dbConfig, migrationsDir);
|
||||
// Override the global variable DB
|
||||
const pg = pgp(dbConfig);
|
||||
await pg.connect();
|
||||
OK("POSTGRES", `Connected to database ${database}!`);
|
||||
return pg;
|
||||
};
|
||||
|
||||
export default await configure();
|
51
lib/database/queries/test_results.js
Normal file
51
lib/database/queries/test_results.js
Normal file
|
@ -0,0 +1,51 @@
|
|||
import pg from "../postgres.js";
|
||||
// Imports
|
||||
import {
|
||||
insertQuery,
|
||||
selectWhereAnyQuery,
|
||||
updateWhereAnyQuery,
|
||||
} from "../pg-query.js";
|
||||
// Constants
|
||||
const table = "test_results";
|
||||
// Queries
|
||||
export const insertTestResult = (testResult) => {
|
||||
const {
|
||||
test_name,
|
||||
test_class,
|
||||
test_method,
|
||||
test_path,
|
||||
test_type,
|
||||
test_timestamp,
|
||||
test_retry,
|
||||
origin,
|
||||
failed,
|
||||
failed_message,
|
||||
screenshot_url,
|
||||
expected_screenshot_url,
|
||||
weblog_url,
|
||||
} = testResult;
|
||||
|
||||
var query = insertQuery(table, {
|
||||
test_name,
|
||||
test_class,
|
||||
test_method,
|
||||
test_path,
|
||||
test_type,
|
||||
test_timestamp,
|
||||
test_retry,
|
||||
origin,
|
||||
failed,
|
||||
failed_message,
|
||||
screenshot_url,
|
||||
expected_screenshot_url,
|
||||
weblog_url,
|
||||
});
|
||||
|
||||
query += "\n RETURNING *";
|
||||
return pg.query(query);
|
||||
};
|
||||
|
||||
export const getCurrentlyFailing = () => {
|
||||
const query = "SELECT *";
|
||||
return pg.query(query);
|
||||
};
|
1
lib/index.js
Normal file
1
lib/index.js
Normal file
|
@ -0,0 +1 @@
|
|||
export { default } from "./core/Qualiteer.js";
|
27
lib/rabbit/TestResultsConsumer.js
Normal file
27
lib/rabbit/TestResultsConsumer.js
Normal file
|
@ -0,0 +1,27 @@
|
|||
// Imports
|
||||
import { RabbitConsumer } from "rabiteer";
|
||||
// Class
|
||||
export default class TestResultsConsumer extends RabbitConsumer {
|
||||
constructor() {
|
||||
super("TestResults");
|
||||
}
|
||||
|
||||
/* Example Test Result
|
||||
{
|
||||
testName: “SomeTest”,
|
||||
testClass: “SomeClass”,
|
||||
testMethod: “SomeMethod”,
|
||||
testType: “API/UI”,
|
||||
testTimestamp: 123893024,
|
||||
origin: “TestSuite”,
|
||||
failed: true,
|
||||
failedMessage: “Some Failure”,
|
||||
screenshotUrl: “https://screenshot”,
|
||||
expectedScreenshotUrl: “https://expected”
|
||||
consoleLogUrl: “https://consolelog”
|
||||
}
|
||||
*/
|
||||
onMessage(testResult) {
|
||||
console.log(testResult);
|
||||
}
|
||||
}
|
9
lib/routes/results-route.js
Normal file
9
lib/routes/results-route.js
Normal file
|
@ -0,0 +1,9 @@
|
|||
import express from "express";
|
||||
import { getCurrentlyFailing } from "../database/queries/test_results.js";
|
||||
const router = express.Router();
|
||||
|
||||
router.get("/failing", (req, res) => {
|
||||
res.send([]);
|
||||
});
|
||||
|
||||
export default router;
|
75
lib/sockets/clients/Executor.js
Normal file
75
lib/sockets/clients/Executor.js
Normal file
|
@ -0,0 +1,75 @@
|
|||
import { Manager } from "socket.io-client";
|
||||
import cp from "child_process";
|
||||
|
||||
import modes from "../modes.js";
|
||||
import events from "../events.js";
|
||||
|
||||
export { default as events } from "../events.js";
|
||||
export { default as modes } from "../modes.js";
|
||||
|
||||
// Data Stream Types
|
||||
const ERR = "e";
|
||||
const OUT = "o";
|
||||
|
||||
export default class Executor {
|
||||
constructor(url, job, options = {}) {
|
||||
this.url = url;
|
||||
this.job = job;
|
||||
this.mode = modes.EXEC;
|
||||
|
||||
// Internal Buffer
|
||||
this.buf = {};
|
||||
this.buf[ERR] = "";
|
||||
this.buf[OUT] = "";
|
||||
|
||||
// Methods
|
||||
this.spawn = options.spawn ?? this.spawn.bind(this);
|
||||
this.report = options.report ?? this.report.bind(this);
|
||||
this.onProcClose = options.onProcClose ?? this.onProcClose.bind(this);
|
||||
this.onClose = options.onClose ?? this.onClose.bind(this);
|
||||
}
|
||||
|
||||
spawn() {
|
||||
const cmdArgs = this.job.command.split(" ");
|
||||
const cmd = cmdArgs.shift();
|
||||
this.proc = cp.spawn(cmd, cmdArgs);
|
||||
|
||||
// Set Encoding
|
||||
this.proc.stdout.setEncoding("utf8");
|
||||
this.proc.stderr.setEncoding("utf8");
|
||||
|
||||
// Process Events
|
||||
this.proc.stdout.on("data", (d) => this.report(d.toString(), OUT));
|
||||
this.proc.stderr.on("data", (d) => this.report(d.toString(), ERR));
|
||||
this.proc.on("close", this.onProcClose);
|
||||
}
|
||||
|
||||
runJob() {
|
||||
const mgr = new Manager(this.url, {
|
||||
query: { mode: this.mode, jobId: this.job.id },
|
||||
});
|
||||
this.socket = mgr.socket("/");
|
||||
this.socket.on("connect", this.spawn);
|
||||
this.socket.on("disconnect", this.onClose);
|
||||
}
|
||||
|
||||
onClose() {
|
||||
console.log("Server disconnected, terminating process.");
|
||||
this.proc.kill("SIGINT");
|
||||
}
|
||||
|
||||
onProcClose(code) {
|
||||
this.socket.emit(events.JOB_CLS, code);
|
||||
console.log(`Process finished with code ${code}`);
|
||||
this.socket.disconnect();
|
||||
}
|
||||
|
||||
report(d, dType) {
|
||||
this.buf[dType] += d;
|
||||
if (!this.buf[dType].includes("\n")) return;
|
||||
this.socket.emit(events.JOB_REP, this.buf[dType]);
|
||||
if (dType === ERR) console.error(`err: ${this.buf[dType]}`);
|
||||
else console.log(`out: ${this.buf[dType]}`);
|
||||
this.buf[dType] = "";
|
||||
}
|
||||
}
|
34
lib/sockets/clients/Initiator.js
Normal file
34
lib/sockets/clients/Initiator.js
Normal file
|
@ -0,0 +1,34 @@
|
|||
import { Manager } from "socket.io-client";
|
||||
import modes from "../modes.js";
|
||||
import events from "../events.js";
|
||||
|
||||
export { default as events } from "../events.js";
|
||||
export { default as modes } from "../modes.js";
|
||||
|
||||
export default class Initiator {
|
||||
constructor(url, options = {}) {
|
||||
this.url = url;
|
||||
this.mode = modes.INIT;
|
||||
this.onLog = options.onLog ?? ((d) => console.log(`job: ${d}`));
|
||||
this.onClose = options.onClose ?? (() => {});
|
||||
this.onCreate = options.onCreate ?? ((id) => console.log(`job id: ${id}`));
|
||||
}
|
||||
|
||||
async newJob(jobRequest, onLog, onClose, onCreate) {
|
||||
const mgr = new Manager(this.url, {
|
||||
query: { mode: this.mode, job: JSON.stringify(jobRequest) },
|
||||
});
|
||||
onLog = onLog ?? this.onLog.bind(this);
|
||||
onClose = onClose ?? this.onClose.bind(this);
|
||||
onCreate = onCreate ?? this.onCreate.bind(this);
|
||||
const sk = mgr.socket("/");
|
||||
sk.on(events.JOB_LOG, onLog);
|
||||
sk.on(events.JOB_CLS, onClose);
|
||||
return new Promise((res) =>
|
||||
sk.on(events.JOB_CRT, function onJobCreate(id) {
|
||||
onCreate(id);
|
||||
res({ ...jobRequest, id });
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
27
lib/sockets/clients/Viewer.js
Normal file
27
lib/sockets/clients/Viewer.js
Normal file
|
@ -0,0 +1,27 @@
|
|||
import { Manager } from "socket.io-client";
|
||||
import modes from "../modes.js";
|
||||
import events from "../events.js";
|
||||
|
||||
export { default as events } from "../events.js";
|
||||
export { default as modes } from "../modes.js";
|
||||
|
||||
export default class Viewer {
|
||||
constructor(url, options = {}) {
|
||||
this.url = url;
|
||||
this.mode = modes.VIEW;
|
||||
this.onLog = options.onLog ?? console.log;
|
||||
this.onClose = options.onClose ?? (() => {});
|
||||
}
|
||||
|
||||
viewJob(jobId, onLog, onClose) {
|
||||
const mgr = new Manager(this.url, {
|
||||
query: { mode: this.mode, jobId },
|
||||
});
|
||||
onLog = onLog ?? this.onLog.bind(this);
|
||||
onClose = onClose ?? this.onClose.bind(this);
|
||||
const sk = mgr.socket("/");
|
||||
sk.on(events.JOB_LOG, onLog);
|
||||
sk.on(events.JOB_CLS, onClose);
|
||||
return sk;
|
||||
}
|
||||
}
|
5
lib/sockets/clients/index.js
Normal file
5
lib/sockets/clients/index.js
Normal file
|
@ -0,0 +1,5 @@
|
|||
export { default as Initiator } from "./Initiator.js";
|
||||
|
||||
export { default as Viewer } from "./Viewer.js";
|
||||
|
||||
export { default as Executor } from "./Executor.js";
|
3
lib/sockets/clients/web.index.js
Normal file
3
lib/sockets/clients/web.index.js
Normal file
|
@ -0,0 +1,3 @@
|
|||
export { default as Initiator } from "./Initiator.js";
|
||||
|
||||
export { default as Viewer } from "./Viewer.js";
|
13
lib/sockets/events.js
Normal file
13
lib/sockets/events.js
Normal file
|
@ -0,0 +1,13 @@
|
|||
const JOB_REP = "jr"; // Job Report Event
|
||||
const JOB_LOG = "jl"; // Job Log Event
|
||||
const JOB_CLS = "jc"; // Job Close Event
|
||||
const JOB_CRT = "jcr"; // Job Create Event
|
||||
const ERR = "e"; // Socket Error
|
||||
|
||||
export default {
|
||||
JOB_REP,
|
||||
JOB_LOG,
|
||||
JOB_CLS,
|
||||
JOB_CRT,
|
||||
ERR,
|
||||
};
|
48
lib/sockets/handler.js
Normal file
48
lib/sockets/handler.js
Normal file
|
@ -0,0 +1,48 @@
|
|||
import { Server as Skio } from "socket.io";
|
||||
import evt from "./events.js";
|
||||
import modes from "./modes.js";
|
||||
|
||||
import { initiator, executor, viewer } from "./modifiers.js";
|
||||
|
||||
const socketDrop = (io, room, id) => {
|
||||
const { rooms } = io.of("/").adapter;
|
||||
const clients = rooms.get(room);
|
||||
if (clients.size > 1 || clients.size === 0) return;
|
||||
const socketId = Array.from(clients)[0];
|
||||
const s = io.sockets.sockets.get(socketId);
|
||||
s.disconnect();
|
||||
};
|
||||
|
||||
const socketConnect = (io, socket, jobs) => {
|
||||
const { mode } = socket.handshake.query;
|
||||
switch (mode) {
|
||||
case modes.INIT:
|
||||
initiator(socket, jobs);
|
||||
break;
|
||||
case modes.EXEC:
|
||||
executor(io, socket, jobs);
|
||||
break;
|
||||
case modes.VIEW:
|
||||
viewer(socket);
|
||||
break;
|
||||
default:
|
||||
socket.send(evt.ERR, "Invalid Mode!");
|
||||
socket.disconnect();
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
const socketAuth = (socket, next) => {
|
||||
const { token } = socket.handshake.auth;
|
||||
// next(new Error("Bad Token"));
|
||||
next();
|
||||
};
|
||||
|
||||
const applySockets = (server, jobs, options) => {
|
||||
const io = new Skio(server);
|
||||
io.on("connection", (socket) => socketConnect(io, socket, jobs));
|
||||
io.of("/").adapter.on("leave-room", (room, id) => socketDrop(io, room, id));
|
||||
return io;
|
||||
};
|
||||
|
||||
export default applySockets;
|
8
lib/sockets/modes.js
Normal file
8
lib/sockets/modes.js
Normal file
|
@ -0,0 +1,8 @@
|
|||
const INIT = "i"; // Intiator Socket
|
||||
const EXEC = "e"; // Execution Socket
|
||||
const VIEW = "v"; // View Socket
|
||||
export default {
|
||||
INIT,
|
||||
EXEC,
|
||||
VIEW,
|
||||
};
|
34
lib/sockets/modifiers.js
Normal file
34
lib/sockets/modifiers.js
Normal file
|
@ -0,0 +1,34 @@
|
|||
import evt from "./events.js";
|
||||
|
||||
export const initiator = (socket, jobs) => {
|
||||
const jobStr = socket.handshake.query.job;
|
||||
const jobReq = JSON.parse(jobStr);
|
||||
|
||||
if (!jobReq || !(jobReq instanceof Object))
|
||||
throw Error("No 'job' was included in the handshake query");
|
||||
|
||||
const job = jobs.newJob(jobReq, socket.id);
|
||||
socket.join(job.id);
|
||||
socket.emit(evt.JOB_CRT, job.id);
|
||||
};
|
||||
|
||||
export const executor = (io, socket, jobs) => {
|
||||
const jobId = socket.handshake.query.jobId;
|
||||
if (!jobId) throw Error("No 'jobId' was included in the handshake query");
|
||||
|
||||
socket.join(jobId);
|
||||
socket.on(evt.JOB_REP, function onReport(log) {
|
||||
jobs.pushLog(jobId, log);
|
||||
io.to(jobId).emit(evt.JOB_LOG, log);
|
||||
});
|
||||
socket.on(evt.JOB_CLS, function onClose(code) {
|
||||
jobs.closeJob(jobId, code);
|
||||
io.to(jobId).emit(evt.JOB_CLS, code);
|
||||
});
|
||||
};
|
||||
|
||||
export const viewer = (socket) => {
|
||||
const jobId = socket.handshake.query.jobId;
|
||||
if (!jobId) throw Error("No 'jobId' was included in the handshake query");
|
||||
socket.join(jobId);
|
||||
};
|
28
lib/util/logging.js
Normal file
28
lib/util/logging.js
Normal file
|
@ -0,0 +1,28 @@
|
|||
// Imports
|
||||
import { Chalk } from "chalk";
|
||||
const { redBright, greenBright, yellowBright, cyanBright, magentaBright } =
|
||||
new Chalk({ level: 2 });
|
||||
|
||||
// Logging
|
||||
const logColor = (color, header, ...args) =>
|
||||
console.log(color(header), ...args);
|
||||
|
||||
export const logError = (...args) => logColor(redBright, ...args);
|
||||
|
||||
export const logConfirm = (...args) => logColor(greenBright, ...args);
|
||||
|
||||
export const logWarn = (...args) => logColor(yellowBright, ...args);
|
||||
|
||||
export const logInfo = (...args) => logColor(cyanBright, ...args);
|
||||
|
||||
export const logVerbose = (...args) => logColor(magentaBright, ...args);
|
||||
|
||||
export const ERR = (header, ...args) => logError(`[${header}]`, ...args);
|
||||
|
||||
export const OK = (header, ...args) => logConfirm(`[${header}]`, ...args);
|
||||
|
||||
export const WARN = (header, ...args) => logWarn(`[${header}]`, ...args);
|
||||
|
||||
export const INFO = (header, ...args) => logInfo(`[${header}]`, ...args);
|
||||
|
||||
export const VERB = (header, ...args) => logVerbose(`[${header}]`, ...args);
|
3
nodemon.json
Normal file
3
nodemon.json
Normal file
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"ignore": ["src/"]
|
||||
}
|
31511
package-lock.json
generated
Normal file
31511
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
66
package.json
Normal file
66
package.json
Normal file
|
@ -0,0 +1,66 @@
|
|||
{
|
||||
"name": "qualiteer",
|
||||
"version": "1.0.0",
|
||||
"description": "QA Data Management",
|
||||
"type": "module",
|
||||
"exports": {
|
||||
".": "./lib/index.js",
|
||||
"./clients": "./lib/sockets/clients/index.js",
|
||||
"./web-clients": "./lib/sockets/clients/web.index.js"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "node bin/app.js",
|
||||
"start:dev": "nodemon bin/app.js",
|
||||
"start:dev:replit": "npm run start:dev & npm run start:react:replit",
|
||||
"start:react": "react-scripts start",
|
||||
"start:react:replit": "DANGEROUSLY_DISABLE_HOST_CHECK=true npm run start:react",
|
||||
"test": "node tests/index.js",
|
||||
"test:dev": "nodemon tests/index.js"
|
||||
},
|
||||
"bin": {
|
||||
"qualiteer": "./bin/app.js"
|
||||
},
|
||||
"author": "Dunemask",
|
||||
"license": "LGPL-2.1-only",
|
||||
"optionalDependencies": {
|
||||
"rabbiteer": "^1.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@mui/icons-material": "^5.6.2",
|
||||
"amqplib": "^0.8.0",
|
||||
"chalk": "^5.0.1",
|
||||
"dotenv": "^16.0.0",
|
||||
"express": "^4.17.2",
|
||||
"figlet": "^1.5.2",
|
||||
"moment": "^2.29.3",
|
||||
"pg-promise": "^10.11.1",
|
||||
"postgres-migrations": "^5.3.0",
|
||||
"socket.io": "^4.4.1",
|
||||
"socket.io-client": "^4.4.1",
|
||||
"uuid": "^8.3.2"
|
||||
},
|
||||
"proxy": "http://localhost:52000/",
|
||||
"devDependencies": {
|
||||
"@emotion/react": "^11.9.0",
|
||||
"@emotion/styled": "^11.8.1",
|
||||
"@mui/material": "^5.6.4",
|
||||
"http-proxy-middleware": "^2.0.6",
|
||||
"nodemon": "^2.0.15",
|
||||
"react": "^18.1.0",
|
||||
"react-dom": "^18.1.0",
|
||||
"react-scripts": "^5.0.1",
|
||||
"readline-sync": "^1.4.10"
|
||||
},
|
||||
"browserslist": {
|
||||
"production": [
|
||||
">0.2%",
|
||||
"not dead",
|
||||
"not op_mini all"
|
||||
],
|
||||
"development": [
|
||||
"last 1 chrome version",
|
||||
"last 1 firefox version",
|
||||
"last 1 safari version"
|
||||
]
|
||||
}
|
||||
}
|
BIN
public/assets/QA.jpg
Normal file
BIN
public/assets/QA.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 18 KiB |
13
public/index.html
Normal file
13
public/index.html
Normal file
|
@ -0,0 +1,13 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<meta name="description" content="Quality Tracked Right" />
|
||||
<title>Qualiteer</title>
|
||||
</head>
|
||||
<body>
|
||||
<noscript>You need to enable JavaScript to run Qualiteer</noscript>
|
||||
<div id="root"></div>
|
||||
</body>
|
||||
</html>
|
8
replit.nix
Normal file
8
replit.nix
Normal file
|
@ -0,0 +1,8 @@
|
|||
{ pkgs }: {
|
||||
deps = [
|
||||
pkgs.nodejs-16_x
|
||||
pkgs.nodePackages.typescript-language-server
|
||||
pkgs.nodePackages.yarn
|
||||
pkgs.replitPackages.jest
|
||||
];
|
||||
}
|
6
scripts/rabbiteer.sh
Executable file
6
scripts/rabbiteer.sh
Executable file
|
@ -0,0 +1,6 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Install Rabbiteer from Gitlab
|
||||
npm i git+https://gitlab.com/Dunemask/rabbiteer.git
|
||||
|
||||
|
23
src/Dashboard.jsx
Normal file
23
src/Dashboard.jsx
Normal file
|
@ -0,0 +1,23 @@
|
|||
import { useContext } from "react";
|
||||
|
||||
// Import Contexts
|
||||
import { JobProvider } from "./ctx/JobContext.jsx";
|
||||
import { ViewProvider } from "./ctx/ViewContext.jsx";
|
||||
import { StoreProvider } from "./ctx/StoreContext.jsx";
|
||||
|
||||
// Import Views
|
||||
import Views from "./Views.jsx";
|
||||
|
||||
export default function Dashboard() {
|
||||
return (
|
||||
<div className="qualiteer">
|
||||
<JobProvider>
|
||||
<StoreProvider>
|
||||
<ViewProvider>
|
||||
<Views />
|
||||
</ViewProvider>
|
||||
</StoreProvider>
|
||||
</JobProvider>
|
||||
</div>
|
||||
);
|
||||
}
|
95
src/Views.jsx
Normal file
95
src/Views.jsx
Normal file
|
@ -0,0 +1,95 @@
|
|||
import { useContext, useState } from "react";
|
||||
import ViewContext from "./ctx/ViewContext.jsx";
|
||||
|
||||
import * as React from 'react';
|
||||
import AppBar from '@mui/material/AppBar';
|
||||
import Box from '@mui/material/Box';
|
||||
import Toolbar from '@mui/material/Toolbar';
|
||||
import IconButton from '@mui/material/IconButton';
|
||||
import Typography from '@mui/material/Typography';
|
||||
import Menu from '@mui/material/Menu';
|
||||
import MenuIcon from '@mui/icons-material/Menu';
|
||||
import Container from '@mui/material/Container';
|
||||
import Avatar from '@mui/material/Avatar';
|
||||
import Button from '@mui/material/Button';
|
||||
import Tooltip from '@mui/material/Tooltip';
|
||||
import MenuItem from '@mui/material/MenuItem';
|
||||
import Drawer from '@mui/material/Drawer';
|
||||
import ListItem from '@mui/material/ListItem';
|
||||
import ListItemIcon from '@mui/material/ListItemIcon';
|
||||
import ListItemText from '@mui/material/ListItemText';
|
||||
import List from '@mui/material/List';
|
||||
import ListItemButton from '@mui/material/ListItemButton';
|
||||
import NotificationsIcon from '@mui/icons-material/Notifications';
|
||||
import WorkIcon from '@mui/icons-material/Work';
|
||||
import FormatListBulletedIcon from '@mui/icons-material/FormatListBulleted';
|
||||
import SettingsIcon from '@mui/icons-material/Settings';
|
||||
import ErrorIcon from '@mui/icons-material/Error';
|
||||
|
||||
const pages = ["failing", "alerting", "jobs", "tests", "settings"];
|
||||
const icons = [ErrorIcon , NotificationsIcon, WorkIcon,FormatListBulletedIcon, SettingsIcon];
|
||||
|
||||
export default function Views() {
|
||||
const [view, setView] = useState(pages[0]);
|
||||
const [drawerOpen, setDrawer] = React.useState(false);
|
||||
|
||||
const toggleDrawer = () => setDrawer(!drawerOpen);
|
||||
const closeDrawer = () => setDrawer(false);
|
||||
const openPage = (e) => setView(e.target.outerText.toLowerCase());
|
||||
|
||||
return (
|
||||
<AppBar position="static" color="secondary">
|
||||
<Container maxWidth="xl">
|
||||
<Toolbar disableGutters>
|
||||
<Drawer
|
||||
open={drawerOpen}
|
||||
onClose={closeDrawer}
|
||||
> <Box
|
||||
sx={{ width: 250 }}
|
||||
role="presentation"
|
||||
>
|
||||
<List>
|
||||
{pages.map((text, index) => (
|
||||
<ListItemButton key={text} onClick={openPage} selected={view===text}>
|
||||
<ListItemIcon>
|
||||
{/*icons[index]*/}
|
||||
</ListItemIcon>
|
||||
<ListItemText primary={text.charAt(0).toUpperCase() + text.slice(1)} />
|
||||
</ListItemButton>
|
||||
))}
|
||||
</List></Box>
|
||||
</Drawer>
|
||||
<IconButton
|
||||
size="large"
|
||||
edge="start"
|
||||
color="inherit"
|
||||
aria-label="menu"
|
||||
sx={{ mr: 2 }}
|
||||
onClick={toggleDrawer}
|
||||
>
|
||||
<MenuIcon />
|
||||
</IconButton>
|
||||
<Typography
|
||||
variant="h6"
|
||||
noWrap
|
||||
component="div"
|
||||
sx={{ mr: 2, display: { xs: 'none', md: 'flex' } }}
|
||||
>
|
||||
{view.charAt(0).toUpperCase() + view.slice(1)}
|
||||
</Typography>
|
||||
<Typography
|
||||
variant="h6"
|
||||
noWrap
|
||||
component="div"
|
||||
sx={{ flexGrow: 1, display: { xs: 'flex', md: 'none' } }}
|
||||
>
|
||||
{view.charAt(0).toUpperCase() + view.slice(1)}
|
||||
</Typography>
|
||||
<Box sx={{ flexGrow: 0 }}>
|
||||
<Avatar alt="Remy Sharp" src="/assets/QA.jpg" />
|
||||
</Box>
|
||||
</Toolbar>
|
||||
</Container>
|
||||
</AppBar>
|
||||
);
|
||||
}
|
57
src/ctx/JobContext.jsx
Normal file
57
src/ctx/JobContext.jsx
Normal file
|
@ -0,0 +1,57 @@
|
|||
import React, { useReducer, createContext, useMemo } from "react";
|
||||
const JobContext = createContext();
|
||||
|
||||
const ACTIONS = {
|
||||
CREATE: "c",
|
||||
UPDATE: "u",
|
||||
DELETE: "d",
|
||||
};
|
||||
|
||||
const initialState = {
|
||||
jobs: [],
|
||||
};
|
||||
|
||||
const reducer = (state, action) => {
|
||||
// Current Jobs
|
||||
const { jobs } = state;
|
||||
var jobIndex;
|
||||
// Actions
|
||||
switch (action.type) {
|
||||
case ACTIONS.CREATE:
|
||||
jobs.push(action.job);
|
||||
return { ...state, jobs };
|
||||
|
||||
case ACTIONS.UPDATE:
|
||||
jobIndex = jobs.find((j) => j.id === (action.job.id ?? action.jobId));
|
||||
jobs[jobIndex] = action.job;
|
||||
return { ...state, jobs };
|
||||
|
||||
case ACTIONS.DELETE:
|
||||
jobIndex = jobs.find((j) => j.id === action.jobId);
|
||||
jobs.splice(jobIndex, 1);
|
||||
return { ...state, jobs };
|
||||
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
||||
|
||||
export const JobProvider = ({ children }) => {
|
||||
const [state, dispatch] = useReducer(reducer, initialState);
|
||||
|
||||
const context = {
|
||||
state,
|
||||
dispatch,
|
||||
jobUpdate: (job, jobId) => dispatch({ type: ACTIONS.UPDATE, jobId, job }),
|
||||
jobCreate: (job) =>
|
||||
dispatch({ type: ACTIONS.CREATE, job: { ...job, log: [] } }),
|
||||
jobDelete: (jobId) => dispatch({ type: ACTIONS.DELETE, jobId }),
|
||||
};
|
||||
const contextValue = useMemo(() => context, [state, dispatch]);
|
||||
|
||||
return (
|
||||
<JobContext.Provider value={contextValue}>{children}</JobContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
export default JobContext;
|
37
src/ctx/StoreContext.jsx
Normal file
37
src/ctx/StoreContext.jsx
Normal file
|
@ -0,0 +1,37 @@
|
|||
import React, { useReducer, createContext, useMemo } from "react";
|
||||
const StoreContext = createContext();
|
||||
|
||||
const ACTIONS = {
|
||||
UPDATE: "u",
|
||||
};
|
||||
|
||||
const initialState = {};
|
||||
|
||||
const reducer = (state, action) => {
|
||||
// Actions
|
||||
switch (action.type) {
|
||||
case ACTIONS.UPDATE:
|
||||
return { ...state, ...store };
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
||||
|
||||
export const StoreProvider = ({ children }) => {
|
||||
const [state, dispatch] = useReducer(reducer, initialState);
|
||||
|
||||
const context = {
|
||||
state,
|
||||
dispatch,
|
||||
updateStore: (store) => dispatch(state, { type: ACTIONS.UPDATE, store }),
|
||||
};
|
||||
const contextValue = useMemo(() => context, [state, dispatch]);
|
||||
|
||||
return (
|
||||
<StoreContext.Provider value={contextValue}>
|
||||
{children}
|
||||
</StoreContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
export default StoreContext;
|
32
src/ctx/ViewContext.jsx
Normal file
32
src/ctx/ViewContext.jsx
Normal file
|
@ -0,0 +1,32 @@
|
|||
import React, { useReducer, createContext, useMemo } from "react";
|
||||
const ViewContext = createContext();
|
||||
|
||||
const ACTIONS = {
|
||||
UPDATE: "u",
|
||||
};
|
||||
|
||||
const initialState = {
|
||||
activePage: "Home",
|
||||
};
|
||||
|
||||
const reducer = (state, action) => {
|
||||
// Actions
|
||||
switch (action.type) {
|
||||
case ACTIONS.UPDATE:
|
||||
return { ...state };
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
||||
|
||||
export const ViewProvider = ({ children }) => {
|
||||
const [state, dispatch] = useReducer(reducer, initialState);
|
||||
|
||||
const contextValue = useMemo(() => ({ state, dispatch }), [state, dispatch]);
|
||||
|
||||
return (
|
||||
<ViewContext.Provider value={contextValue}>{children}</ViewContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
export default ViewContext;
|
7
src/index.js
Normal file
7
src/index.js
Normal file
|
@ -0,0 +1,7 @@
|
|||
import { createRoot } from "react-dom/client";
|
||||
import Dashboard from "./Dashboard.jsx";
|
||||
|
||||
const appRoot = document.getElementById("root");
|
||||
const root = createRoot(appRoot);
|
||||
|
||||
root.render(<Dashboard />);
|
14
src/runner/JobDisplay.jsx
Normal file
14
src/runner/JobDisplay.jsx
Normal file
|
@ -0,0 +1,14 @@
|
|||
function jobDisplay({ props }) {
|
||||
return (
|
||||
<div className="job">
|
||||
<h2>Job ID: {props.job.id}</h2>
|
||||
<h3>Log: </h3>
|
||||
{props.job.log.map((l, i) => (
|
||||
<div className="line" key={i}>
|
||||
{l}
|
||||
<br />
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
49
src/runner/JobView.jsx
Normal file
49
src/runner/JobView.jsx
Normal file
|
@ -0,0 +1,49 @@
|
|||
import { useContext } from "react";
|
||||
import { Initiator } from "qualiteer/web-clients";
|
||||
import JobContext, { ACTIONS as jobActions } from "../../ctx/JobContext.jsx";
|
||||
|
||||
const cmd = `node other.js`;
|
||||
export default function Test() {
|
||||
const { state: jobState, dispatch: jobDispatch } = useContext(JobContext);
|
||||
|
||||
function onLog(d) {
|
||||
const job = jobState.jobs[0];
|
||||
job.log.push(d);
|
||||
jobDispatch({ type: jobActions.UPDATE, jobId: jobState.jobs[0].id, job });
|
||||
console.log(d);
|
||||
console.log(jobState);
|
||||
}
|
||||
|
||||
async function startJob() {
|
||||
console.log("Wanting to start");
|
||||
const url = "https://Qualiteer.elijahparker3.repl.co";
|
||||
// Create an initiator and make a job request
|
||||
const primary = new Initiator(url);
|
||||
const jobRequest = { command: cmd };
|
||||
|
||||
const job = await primary.newJob(jobRequest, onLog, () =>
|
||||
console.log("Primary Job Concluded")
|
||||
);
|
||||
jobDispatch({ type: jobActions.CREATE, job: { ...job, log: [] } });
|
||||
|
||||
console.log("Started");
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="Jobs">
|
||||
<h1>vv Info vv </h1>
|
||||
<button onClick={startJob}>Start</button>
|
||||
{jobState.jobs.map((j) =>
|
||||
j.log.map((l, i) => (
|
||||
<div className="line" key={i}>
|
||||
{l}
|
||||
<br />
|
||||
</div>
|
||||
))
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
|
||||
/*
|
||||
}*/
|
||||
}
|
22
tests/index.js
Normal file
22
tests/index.js
Normal file
|
@ -0,0 +1,22 @@
|
|||
#!/usr/bin/env node
|
||||
import "dotenv/config"; // Load Envars
|
||||
import Qualiteer from "qualiteer";
|
||||
import { Initiator, Executor } from "qualiteer/clients";
|
||||
|
||||
// Start server
|
||||
const qltr = new Qualiteer();
|
||||
await qltr.start();
|
||||
|
||||
const url = "https://Qualiteer.elijahparker3.repl.co";
|
||||
|
||||
// Create an initiator and make a job request
|
||||
const primary = new Initiator(url);
|
||||
const job = { command: "ls -la" };
|
||||
await primary.newJob(job, null, () => console.log("Primary Job Concluded"));
|
||||
const { clients } = qltr.jobs;
|
||||
const skId = Object.keys(clients)[0];
|
||||
const { jobs } = clients[skId];
|
||||
const serverJob = jobs[0];
|
||||
|
||||
const exec = new Executor(url, serverJob);
|
||||
exec.runJob();
|
Loading…
Add table
Add a link
Reference in a new issue