Rewrote k8s handling
This commit is contained in:
parent
dd97d013cb
commit
bb6a6396dc
7 changed files with 100 additions and 95 deletions
|
@ -1,8 +1,11 @@
|
|||
import { v4 } from "uuid";
|
||||
import applyJob from "./k8s/kubernetes.js";
|
||||
import applyJobInternally from "./k8s/k8s-internal.js";
|
||||
import applyJob from "./k8s/k8s.js";
|
||||
import buildJob from "./job-builder.js";
|
||||
|
||||
const maxJobs = process.env.MAX_JOBS ? parseInt(process.env.MAX_JOBS) : 3;
|
||||
const internalDeploy = process.env.INTERNAL_DEPLOY === "true";
|
||||
const launchJob = internalDeploy ? applyJobInternally : applyJob;
|
||||
|
||||
class JobManager {
|
||||
constructor() {
|
||||
|
@ -36,18 +39,11 @@ class JobManager {
|
|||
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 = buildJob(jobRequest, id);
|
||||
job.id = v4();
|
||||
job.log = [];
|
||||
this.clients[id].jobs.push(job);
|
||||
applyJob(job);
|
||||
launchJob(job);
|
||||
return { ...job };
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue