adding socket listner dataset screen
This commit is contained in:
parent
776b6e540e
commit
a2066ce5cd
16 changed files with 127 additions and 50 deletions
|
@ -58,6 +58,8 @@ export class App extends TypedEvent<ServerStatus> {
|
|||
io.on("connection", (socket) => {
|
||||
this.socketSubscribers.map((el) => {
|
||||
el.emitter.on((e) => {
|
||||
console.log(el.event)
|
||||
console.log(e)
|
||||
socket.emit(el.event, e);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -3,6 +3,19 @@ import { extensions } from "../extensions/extensions";
|
|||
extensions();
|
||||
|
||||
export class ExecError extends Error {
|
||||
id?:string;
|
||||
script: string;
|
||||
unixTime: number;
|
||||
type = EXEC_TYPE.EXEC;
|
||||
error: any;
|
||||
|
||||
constructor(script: string, ...args: any) {
|
||||
super(...args);
|
||||
this.script = script;
|
||||
this.unixTime = Date.now();
|
||||
this.error = args.firstElement();
|
||||
}
|
||||
|
||||
static isExecError(e: any): ExecError | void {
|
||||
try {
|
||||
if (e) {
|
||||
|
@ -14,16 +27,6 @@ export class ExecError extends Error {
|
|||
console.log(error);
|
||||
}
|
||||
}
|
||||
script: string;
|
||||
unixTime: number;
|
||||
type = EXEC_TYPE.EXEC;
|
||||
error: any;
|
||||
constructor(script: string, ...args: any) {
|
||||
super(...args);
|
||||
this.script = script;
|
||||
this.unixTime = Date.now();
|
||||
this.error = args.firstElement();
|
||||
}
|
||||
}
|
||||
|
||||
export class SpawnError extends Error {
|
||||
|
|
|
@ -4,6 +4,7 @@ export class ExecutorResult {
|
|||
type: EXEC_TYPE;
|
||||
event: EXEC_EVENT;
|
||||
data: any;
|
||||
id?:string
|
||||
constructor(type: EXEC_TYPE, event: EXEC_EVENT, data: any) {
|
||||
this.type = type;
|
||||
this.event = event;
|
||||
|
|
|
@ -25,7 +25,12 @@ export class ExecutorProgramService
|
|||
this.maxTime = maxTime;
|
||||
}
|
||||
|
||||
private async workerExecuted(command: string, workerType: WorkerType, args: Array<string> | undefined = undefined) {
|
||||
private async workerExecuted(
|
||||
command: string,
|
||||
workerType: WorkerType,
|
||||
args: Array<string> | undefined = undefined,
|
||||
id: string | undefined = undefined
|
||||
) {
|
||||
try {
|
||||
cluster.setupPrimary({
|
||||
exec: __dirname + "/../helpers/worker_computed.js",
|
||||
|
@ -55,6 +60,7 @@ export class ExecutorProgramService
|
|||
const execError = ExecError.isExecError(e);
|
||||
|
||||
if (execError instanceof ExecError) {
|
||||
execError.id = id
|
||||
this.emit(Result.error(execError));
|
||||
this.worker = undefined;
|
||||
return;
|
||||
|
@ -62,6 +68,7 @@ export class ExecutorProgramService
|
|||
|
||||
const executorResult = ExecutorResult.isExecutorResult(e);
|
||||
if (executorResult instanceof ExecutorResult) {
|
||||
executorResult.id = id
|
||||
this.emit(Result.ok(executorResult));
|
||||
this.worker = undefined;
|
||||
return;
|
||||
|
@ -85,13 +92,18 @@ export class ExecutorProgramService
|
|||
if (this.worker) this.worker.kill();
|
||||
this.worker = undefined;
|
||||
}
|
||||
public async call(type: EXEC_TYPE, command: string, args: Array<string> | undefined = undefined): Promise<void> {
|
||||
public async call(
|
||||
type: EXEC_TYPE,
|
||||
command: string,
|
||||
args: Array<string> | undefined = undefined,
|
||||
id: string | undefined = undefined
|
||||
): Promise<void> {
|
||||
if (type == EXEC_TYPE.EXEC) {
|
||||
this.workerExecuted(command, WorkerType.EXEC);
|
||||
this.workerExecuted(command, WorkerType.EXEC, undefined, id);
|
||||
|
||||
return;
|
||||
}
|
||||
this.workerExecuted(command, WorkerType.SPAWN, args);
|
||||
this.workerExecuted(command, WorkerType.SPAWN, args, id);
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ import { EXEC_TYPE, ExecError, SpawnError } from "../models/exec_error_model";
|
|||
import { ExecutorResult } from "../models/executor_result";
|
||||
import { ExecutorProgramService } from "../services/executor_program_service";
|
||||
|
||||
const executorProgramService = new ExecutorProgramService("");
|
||||
export const executorProgramService = new ExecutorProgramService("");
|
||||
export class KillLastProcessUseCase extends CallbackStrategyWithEmpty {
|
||||
call = async (): Promise<Result<undefined, string>> => {
|
||||
executorProgramService.deleteWorker();
|
||||
|
@ -26,6 +26,7 @@ export class ExecProcessUseCase {
|
|||
call = async (
|
||||
path: string,
|
||||
command: string,
|
||||
id:string,
|
||||
watcher?: TypedEvent<Result<ExecError | SpawnError, ExecutorResult>>
|
||||
): Promise<Result<Error, string>> => {
|
||||
try {
|
||||
|
@ -33,7 +34,7 @@ export class ExecProcessUseCase {
|
|||
executorProgramService.on((event) => {
|
||||
if (watcher) watcher.emit(event);
|
||||
});
|
||||
executorProgramService.call(EXEC_TYPE.EXEC, command);
|
||||
executorProgramService.call(EXEC_TYPE.EXEC, command, undefined ,id);
|
||||
|
||||
return Result.ok("ok");
|
||||
} catch (error) {
|
||||
|
|
|
@ -6,8 +6,7 @@ import { MongoIdValidation } from "../../../core/validations/mongo_id_validation
|
|||
import { DatasetDBModel } from "../models/dataset_database_model";
|
||||
import { IDatasetModel } from "../models/dataset_validation_model";
|
||||
import { ProcessWatcherAndDatabaseUpdateService } from "./create_dataset_scenario";
|
||||
import { UpdateDataBaseModelUseCase } from "../../../core/usecases/update_database_model_usecase";
|
||||
|
||||
|
||||
export class ExecDatasetProcessScenario extends CallbackStrategyWithIdQuery {
|
||||
idValidationExpression = new MongoIdValidation();
|
||||
|
||||
|
@ -18,6 +17,7 @@ export class ExecDatasetProcessScenario extends CallbackStrategyWithIdQuery {
|
|||
return new ExecProcessUseCase().call(
|
||||
`${model.project.rootDir}/`,
|
||||
`python3 $PYTHON_BLENDER_PROC --path '${model.project.rootDir}/${model.name}/'`,
|
||||
id,
|
||||
new ProcessWatcherAndDatabaseUpdateService(id as unknown as ObjectId)
|
||||
);
|
||||
});
|
||||
|
|
|
@ -18,6 +18,7 @@ export class UploadCadFileToProjectScenario extends CallbackStrategyWithFileUplo
|
|||
async () =>
|
||||
await new ExecProcessUseCase().call(
|
||||
`${databaseModel.rootDir}/`,
|
||||
'',
|
||||
`python3 $PYTHON_BLENDER --path '${databaseModel.rootDir}/assets/'`
|
||||
)
|
||||
)
|
||||
|
|
|
@ -3,10 +3,10 @@ import { App } from "./core/controllers/app";
|
|||
import { SocketSubscriber } from "./core/controllers/socket_controller";
|
||||
import { extensions } from "./core/extensions/extensions";
|
||||
import { httpRoutes } from "./core/controllers/routes";
|
||||
import { pipelineRealTimeService } from "./features/_realtime/realtime_presentation";
|
||||
|
||||
import { executorProgramService } from "./core/usecases/exec_process_usecase";
|
||||
|
||||
extensions();
|
||||
|
||||
const socketSubscribers = [new SocketSubscriber(pipelineRealTimeService, "realtime")];
|
||||
const socketSubscribers = [new SocketSubscriber(executorProgramService, "realtime")];
|
||||
|
||||
new App(httpRoutes, socketSubscribers).listen();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue