Fixed client disconnect and navigation glitch

This commit is contained in:
Dunemask 2022-08-14 19:23:37 +00:00
parent ecf0516b39
commit a3cb448a7b
8 changed files with 34 additions and 39 deletions

View file

@ -1,4 +1,4 @@
import { Manager } from "socket.io-client";
import io from "socket.io-client";
import cp from "child_process";
import modes from "../modes.js";
@ -46,10 +46,9 @@ export default class Executor {
}
runJob() {
const mgr = new Manager(this.url, {
this.socket = io(this.url, {
query: { mode: this.mode, jobId: this.jobId },
});
this.socket = mgr.socket("/");
this.socket.on("connect", this.spawn);
this.socket.on("disconnect", this.onClose);
}
@ -57,7 +56,6 @@ export default class Executor {
onClose() {
console.log("Server disconnected, terminating process.");
if (this.proc) this.proc.kill("SIGKILL");
}
onProcClose(code) {

View file

@ -1,4 +1,4 @@
import { Manager } from "socket.io-client";
import { io } from "socket.io-client";
import modes from "../modes.js";
import events from "../events.js";
@ -21,17 +21,20 @@ export default class Initiator {
}
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);
this.sk = mgr.socket("/");
this.sk.on(events.JOB_LOG, onLog);
this.sk.on(events.JOB_CLS, onClose);
const sk = io(this.url, {
query: { mode: this.mode, job: JSON.stringify(jobRequest) },
});
sk.on(events.JOB_LOG, onLog);
sk.on(events.JOB_CLS, function onJobClose(c) {
sk.disconnect();
onClose(c);
});
this.sk = sk;
return new Promise((res) =>
this.sk.on(events.JOB_CRT, function onJobCreate(id) {
sk.on(events.JOB_CRT, function onJobCreate(id) {
onCreate(id);
res({ ...jobRequest, id });
})
@ -46,9 +49,6 @@ export default class Initiator {
onPipelineTrigger,
onPipelineClose
) {
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);
@ -85,13 +85,18 @@ export default class Initiator {
}
});
onPipelineClose = onPipelineClose ?? this.onPipelineClose.bind(this);
this.sk = mgr.socket("/");
this.sk.on(events.JOB_LOG, onLog);
this.sk.on(events.JOB_CLS, onClose);
this.sk.on(events.PPL_TRG, onPipelineTrigger);
this.sk.on(events.PPL_CLS, onPipelineClose);
const sk = io(this.url, {
query: { mode: this.mode, job: JSON.stringify(jobRequest) },
});
sk.on(events.JOB_LOG, onLog);
sk.on(events.JOB_CLS, function onJobClose(c) {
sk.disconnect();
onClose(c);
});
sk.on(events.PPL_TRG, onPipelineTrigger);
this.sk = sk;
return new Promise((res) =>
this.sk.on(events.JOB_CRT, function onJobCreate(id) {
sk.on(events.JOB_CRT, function onJobCreate(id) {
onCreate(id);
res({ ...jobRequest, id });
})

View file

@ -1,4 +1,4 @@
import { Manager } from "socket.io-client";
import io from "socket.io-client";
import modes from "../modes.js";
import events from "../events.js";
@ -14,12 +14,11 @@ export default class Viewer {
}
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("/");
const sk = io(this.url, {
query: { mode: this.mode, jobId },
});
sk.on(events.JOB_LOG, onLog);
sk.on(events.JOB_CLS, onClose);
return sk;

View file

@ -3,7 +3,6 @@ const JOB_LOG = "jl"; // Job Log Event
const JOB_CLS = "jc"; // Job Close Event
const JOB_CRT = "jcr"; // Job Create Event
const PPL_TRG = "plr"; // Pipeline Trigger Event
const PPL_CLS = "plc"; // Pipeline Close Event
const ERR = "e"; // Socket Error
export default {
@ -12,6 +11,5 @@ export default {
JOB_CLS,
JOB_CRT,
PPL_TRG,
PPL_CLS,
ERR,
};