Revamp Job flow
This commit is contained in:
parent
945afdfbbe
commit
4a0a4b29a5
86 changed files with 592 additions and 608 deletions
38
lib/common/executor/executor-bundler.js
Normal file
38
lib/common/executor/executor-bundler.js
Normal file
|
@ -0,0 +1,38 @@
|
|||
import { URL } from "node:url";
|
||||
import path from "node:path";
|
||||
import caxa from "caxa";
|
||||
import { rollup } from "rollup";
|
||||
import loadConfigFile from "rollup/loadConfigFile";
|
||||
import { executorLibraryDir, binName, scriptName } from "./executor-config.js";
|
||||
// Fix import
|
||||
const { default: caxaPackage } = caxa;
|
||||
// Rollup Config
|
||||
const rollupConfigPath = path.resolve(executorLibraryDir, "rollup.config.js");
|
||||
|
||||
// Build functions
|
||||
async function packageBin() {
|
||||
console.log("Packaging bundle into binary");
|
||||
return caxaPackage({
|
||||
input: "dist/bundles/",
|
||||
output: `bin/${binName}`,
|
||||
command: ["{{caxa}}/node_modules/.bin/node", `{{caxa}}/${scriptName}`],
|
||||
uncompressionMessage: "Unpacking, please wait...",
|
||||
});
|
||||
}
|
||||
|
||||
async function rollupBundle() {
|
||||
console.log("Rolling up executor into bundle");
|
||||
const { options, warnings } = await loadConfigFile(rollupConfigPath);
|
||||
if (warnings.count !== 0)
|
||||
console.log(`Rollup has ${warnings.count} warnings`);
|
||||
warnings.flush();
|
||||
|
||||
for (const optionsObj of options) {
|
||||
const bundle = await rollup(optionsObj);
|
||||
await Promise.all(optionsObj.output.map(bundle.write));
|
||||
}
|
||||
}
|
||||
|
||||
await rollupBundle();
|
||||
await packageBin();
|
||||
console.log("Done");
|
5
lib/common/executor/executor-config.js
Normal file
5
lib/common/executor/executor-config.js
Normal file
|
@ -0,0 +1,5 @@
|
|||
export const executorLibraryDir = new URL(".", import.meta.url).pathname;
|
||||
export const binName = "qltr-executor";
|
||||
export const configName = "executor.config.mjs";
|
||||
export const scriptName = "qualiteer-executor.mjs";
|
||||
export const entrypointName = "executor-entrypoint.js";
|
17
lib/common/executor/executor-configurator.js
Normal file
17
lib/common/executor/executor-configurator.js
Normal file
|
@ -0,0 +1,17 @@
|
|||
const funcify = (v) => () => v;
|
||||
|
||||
export function verify(config) {
|
||||
for (var k in config) {
|
||||
if (typeof config[k] !== "function")
|
||||
throw Error("All config options must be functions!");
|
||||
}
|
||||
}
|
||||
|
||||
export function normalize(conf) {
|
||||
const config = { ...conf };
|
||||
for (var k in config) {
|
||||
if (typeof config[k] === "function") continue;
|
||||
config[k] = funcify(config[k]);
|
||||
}
|
||||
return config;
|
||||
}
|
14
lib/common/executor/executor-entrypoint.js
Normal file
14
lib/common/executor/executor-entrypoint.js
Normal file
|
@ -0,0 +1,14 @@
|
|||
import path from "node:path";
|
||||
import Executor from "../sockets/clients/Executor.js";
|
||||
import { normalize } from "./executor-configurator.js";
|
||||
import { configName as executorConfigName } from "./executor-config.js";
|
||||
const executorConfigPath = path.resolve(executorConfigName);
|
||||
const { default: executorConfig } = await import(executorConfigPath);
|
||||
|
||||
// Load config and args
|
||||
const args = process.argv.slice(2);
|
||||
const payload = JSON.parse(Buffer.from(args[0], "base64").toString("utf8"));
|
||||
const config = normalize(executorConfig(payload));
|
||||
// Start Executor
|
||||
const exec = new Executor(config, payload);
|
||||
exec.runJob();
|
17
lib/common/executor/rollup.config.js
Normal file
17
lib/common/executor/rollup.config.js
Normal file
|
@ -0,0 +1,17 @@
|
|||
import path from "node:path";
|
||||
import { nodeResolve } from "@rollup/plugin-node-resolve";
|
||||
import commonjs from "@rollup/plugin-commonjs";
|
||||
import { terser } from "rollup-plugin-terser";
|
||||
import {
|
||||
executorLibraryDir,
|
||||
entrypointName,
|
||||
scriptName,
|
||||
} from "./executor-config.js";
|
||||
|
||||
export default {
|
||||
input: path.resolve(executorLibraryDir, entrypointName),
|
||||
output: {
|
||||
file: `dist/bundles/${scriptName}`,
|
||||
},
|
||||
plugins: [nodeResolve(), commonjs(), terser()],
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue